ROOT-LEE
ROOT-LEE
FFilament
Created by ROOT-LEE on 7/18/2024 in #❓┊help
How to Hide Panel Icons Based on User Roles and Order Panels
Finally: ), The solution was to use the excludes() method, https://filamentphp.com/plugins/bezhansalleh-panel-switch#panel-exclusion AppServiceProvider:
use BezhanSalleh\PanelSwitch\PanelSwitch;
....
use App\Models\PanelAccess;
use Filament\Facades\Filament;

PanelSwitch::configureUsing(function (PanelSwitch $panelSwitch) {
$panelSwitch->excludes(function () {
$user = auth()->user();

if ($user && $user->isAdmin()) {
return [];
}

$panels = Filament::getPanels();
$excludedPanels = [];

foreach ($panels as $panel) {
if (!$user->hasPanelAccess($panel->getId())) {
$excludedPanels[] = $panel->getId();
}
}
return $excludedPanels;
});
//...
});

use BezhanSalleh\PanelSwitch\PanelSwitch;
....
use App\Models\PanelAccess;
use Filament\Facades\Filament;

PanelSwitch::configureUsing(function (PanelSwitch $panelSwitch) {
$panelSwitch->excludes(function () {
$user = auth()->user();

if ($user && $user->isAdmin()) {
return [];
}

$panels = Filament::getPanels();
$excludedPanels = [];

foreach ($panels as $panel) {
if (!$user->hasPanelAccess($panel->getId())) {
$excludedPanels[] = $panel->getId();
}
}
return $excludedPanels;
});
//...
});

User:
public function hasPanelAccess($panelId)
{
if ($this->hasRole('super_admin')) {
return true;
}

foreach ($this->roles as $role) {
if (PanelAccess::where('role_id', $role->id)
->whereJsonContains('panel_id', $panelId)
->exists()) {
return true;
}
}

return false;
}

public function hasPanelAccess($panelId)
{
if ($this->hasRole('super_admin')) {
return true;
}

foreach ($this->roles as $role) {
if (PanelAccess::where('role_id', $role->id)
->whereJsonContains('panel_id', $panelId)
->exists()) {
return true;
}
}

return false;
}

PanelAccess
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Spatie\Permission\Models\Role;

class PanelAccess extends Model
{
protected $fillable = ['role_id', 'panel_id'];
protected $casts = [
'panel_id' => 'array',
];
public function role()
{
return $this->belongsTo(Role::class);
}

}
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Spatie\Permission\Models\Role;

class PanelAccess extends Model
{
protected $fillable = ['role_id', 'panel_id'];
protected $casts = [
'panel_id' => 'array',
];
public function role()
{
return $this->belongsTo(Role::class);
}

}
Thank you! 🙏 :fi:
11 replies
FFilament
Created by ROOT-LEE on 7/18/2024 in #❓┊help
How to Hide Panel Icons Based on User Roles and Order Panels
No description
11 replies
FFilament
Created by ROOT-LEE on 7/18/2024 in #❓┊help
How to Hide Panel Icons Based on User Roles and Order Panels
Hi, The icon of a panel represents its resources. I want to hide entire panel (including the icon) if a user’s role doesn’t have access to that panel. The goal is to control visibility dynamically based on user roles.
11 replies
FFilament
Created by Jon Mason on 11/1/2023 in #❓┊help
Tapping into email verification functionality.
Ohh there was a session opened in another tab , everything works fine !!
22 replies
FFilament
Created by Jon Mason on 11/1/2023 in #❓┊help
Tapping into email verification functionality.
Hi, I'm testing the same features. where can i call $this->sendEmailVerificationNotification() ?
I have implemented it. App\Http\Controllers\Auth\EmailVerificationController App\Http\Controllers\Responses\VerificationResponse and UserObserver
public
function created(User $user): void
{


// Check the role of the creator and assign the corresponding role to the new user
if (!auth()->user()->isAdmin()) {
if (auth()->user()->isEtablissement()) {
$user->assignRole('service_commun');


$user->sendEmailVerificationNotification();


} else {
$user->assignRole('etablissement');
}
}


}
public
function created(User $user): void
{


// Check the role of the creator and assign the corresponding role to the new user
if (!auth()->user()->isAdmin()) {
if (auth()->user()->isEtablissement()) {
$user->assignRole('service_commun');


$user->sendEmailVerificationNotification();


} else {
$user->assignRole('etablissement');
}
}


}
Thanks 🙂
22 replies
FFilament
Created by msalehi on 12/3/2023 in #❓┊help
MediaLibrary not working with minIO with docker
It's working. This is my snippet of code. Ressource:
SpatieMediaLibraryFileUpload::make('pdf')
->acceptedFileTypes(['application/pdf'])
->collection('pdf')
->disk('s3')
->downloadable()->previewable()->imageEditor()->visibility('private')
,
SpatieMediaLibraryFileUpload::make('pdf')
->acceptedFileTypes(['application/pdf'])
->collection('pdf')
->disk('s3')
->downloadable()->previewable()->imageEditor()->visibility('private')
,
Config/FileSystem
'default' => env('FILESYSTEM_DISK', 'local'),
//....

Filesystem
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,

],
'default' => env('FILESYSTEM_DISK', 'local'),
//....

Filesystem
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,

],
and the .env file:
AWS_ACCESS_KEY_ID=xxxxxxx
AWS_SECRET_ACCESS_KEY=xxxxxxxxx
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=test
AWS_USE_PATH_STYLE_ENDPOINT=true
AWS_URL=https://server_url/test
AWS_ENDPOINT=https://server_url
MEDIA_DISK=s3
AWS_ACCESS_KEY_ID=xxxxxxx
AWS_SECRET_ACCESS_KEY=xxxxxxxxx
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=test
AWS_USE_PATH_STYLE_ENDPOINT=true
AWS_URL=https://server_url/test
AWS_ENDPOINT=https://server_url
MEDIA_DISK=s3
16 replies
FFilament
Created by code eater on 1/13/2024 in #❓┊help
Manually Upload files
3 replies
FFilament
Created by Emaz on 8/24/2023 in #❓┊help
hidden fields V3
5 replies
FFilament
Created by ROOT-LEE on 8/27/2023 in #❓┊help
Unable to save hidden() fields to database !!
Okay , thank you, i will try it
10 replies
FFilament
Created by ROOT-LEE on 8/27/2023 in #❓┊help
Unable to save hidden() fields to database !!
yes, I agree with you , perfect, so using standard Laravel code to insert data into database ( Fantastic! )
protected function afterCreate(): void
{
// Can I get the current inserted id of this model: Doctorant student?
$doctorant=Doctorant::select('id')->where('code_inscription',$this->data['code_inscription'])
->first()['id'];
if ($doctorant){

//getting data from current instance
$annee_inscription = $this->data['annee_inscription'];
$current_year = $this->data['these']['current_year'];


$montantOctroye = new MontantOctroye();

$montantOctroye->doctorant_id = $doctorant;
$montantOctroye->current_year = $current_year;
$montantOctroye->annee_inscription = $annee_inscription;
$montantOctroye->save();

}
protected function afterCreate(): void
{
// Can I get the current inserted id of this model: Doctorant student?
$doctorant=Doctorant::select('id')->where('code_inscription',$this->data['code_inscription'])
->first()['id'];
if ($doctorant){

//getting data from current instance
$annee_inscription = $this->data['annee_inscription'];
$current_year = $this->data['these']['current_year'];


$montantOctroye = new MontantOctroye();

$montantOctroye->doctorant_id = $doctorant;
$montantOctroye->current_year = $current_year;
$montantOctroye->annee_inscription = $annee_inscription;
$montantOctroye->save();

}
Is there a way to retrieve the inserted id of this instance? Thank you very much for your help🤝 " you can set it in ->afterCreate() or wherever you want to modify the data." was the key
10 replies
FFilament
Created by ROOT-LEE on 8/27/2023 in #❓┊help
Unable to save hidden() fields to database !!
Thank you Koch, Since I'm on the Create page, I used mutateFormDataBeforeCreate(), knowing that I already use beforeCreate() method, I'm not entirely aware of the distinction between them. So by hiding this step(), the data is not saved to the database even using one of these two methods, but when I debug afterCreate() method, I see that the data is populated?? 🤔
10 replies
FFilament
Created by ROOT-LEE on 4/28/2023 in #❓┊help
Storing repeater data in a pivot table
The pivot Model
class DiplomeExpert extends Pivot
{
use HasFactory;

protected $guarded = [];

}
class DiplomeExpert extends Pivot
{
use HasFactory;

protected $guarded = [];

}
The Expert Model with hasMany() relationship
public function diplome_expert(): HasMany
{
return $this->hasMany(DiplomeExpert::class);
}
public function diplome_expert(): HasMany
{
return $this->hasMany(DiplomeExpert::class);
}
Expert Ressource
Forms\Components\Repeater::make('diplome_expert')
->relationship()
->schema([/**/)]
Forms\Components\Repeater::make('diplome_expert')
->relationship()
->schema([/**/)]
God bless you
11 replies
FFilament
Created by ROOT-LEE on 4/28/2023 in #❓┊help
Storing repeater data in a pivot table
Thank you ! Your support means the world
11 replies
FFilament
Created by ROOT-LEE on 4/11/2023 in #❓┊help
Research of null value in relation (belongs to many)
All right, thanks for that suggestion.. 😎
5 replies
FFilament
Created by ROOT-LEE on 4/11/2023 in #❓┊help
Research of null value in relation (belongs to many)
Yes the "querying-relationship-existence" was the key word
$data = Personnel::query()->has('lieuAffectation')->get()->toArray()
$data = Personnel::query()->has('lieuAffectation')->get()->toArray()
This request gives me everyone who doesn't have a location. ------- It is possible to add in a selective filter an option with 'person without having a location' that call the previus query ?
location_1 location_2 location_3 personne_without_locattion
Tables\Filters\SelectFilter::make('id')
->relationship('lastLieuAffectation', 'name_fr')
->multiple()
->label("Lieu d'affectaion")
->options(
LieuAffectation::all()->pluck('name_fr', 'id')->toArray()
),
Tables\Filters\SelectFilter::make('id')
->relationship('lastLieuAffectation', 'name_fr')
->multiple()
->label("Lieu d'affectaion")
->options(
LieuAffectation::all()->pluck('name_fr', 'id')->toArray()
),
5 replies