Dhaval Kacha
Dhaval Kacha
FFilament
Created by Dhaval Kacha on 11/30/2023 in #❓┊help
hide field conditionally and submit values accordingly.
Oh, I have used this method mutateFormDataBeforeCreate() before. Its really great alternative for Hidden or to submit default value. Now my code looks like this.
Fieldset::make('')
->schema([
Select::make('user_id')
->options(
User::with('roles')->whereHas('roles',
function ($query) {
$query->where('name', 'manager');
})->pluck('name','id')
)
->searchable()
->label('Managers')
->hidden(auth()->user()->hasRole('manager')),
])
Fieldset::make('')
->schema([
Select::make('user_id')
->options(
User::with('roles')->whereHas('roles',
function ($query) {
$query->where('name', 'manager');
})->pluck('name','id')
)
->searchable()
->label('Managers')
->hidden(auth()->user()->hasRole('manager')),
])
I've removed if else and added hidden for manager role and adding default value for manager role. Thank you @Dennis Koch , @ChesterS
12 replies
FFilament
Created by Dhaval Kacha on 11/30/2023 in #❓┊help
hide field conditionally and submit values accordingly.
Alright! where to write ->mutateFormDataUsing?
->mutateFormDataUsing(function ($data) {
$data['user_id'] = auth()->id();

return $data;
})
->mutateFormDataUsing(function ($data) {
$data['user_id'] = auth()->id();

return $data;
})
12 replies
FFilament
Created by Dhaval Kacha on 11/30/2023 in #❓┊help
hide field conditionally and submit values accordingly.
Hey, Thank you for your help, I achieved it like this.
if (auth()->user()->hasRole('admin')) {
$field = Select::make('user_id')
->options(
User::with('roles')->whereHas('roles',
function ($query) {
$query->where('name', 'manager');
})->pluck('name','id')
)
->searchable()
->label('Managers');
} else {
$field = Hidden::make('user_id')
->default(auth()->id());
}
if (auth()->user()->hasRole('admin')) {
$field = Select::make('user_id')
->options(
User::with('roles')->whereHas('roles',
function ($query) {
$query->where('name', 'manager');
})->pluck('name','id')
)
->searchable()
->label('Managers');
} else {
$field = Hidden::make('user_id')
->default(auth()->id());
}
and used this $field variable inside schema
Fieldset::make('')
->schema([
$field,
OtherFields...,
])
Fieldset::make('')
->schema([
$field,
OtherFields...,
])
12 replies
FFilament
Created by Dhaval Kacha on 11/23/2023 in #❓┊help
How to add only edit form to a livewire component.
Its working! grateful for your time.
22 replies
FFilament
Created by Dhaval Kacha on 11/23/2023 in #❓┊help
How to add only edit form to a livewire component.
Im trying to edit the name of event . Its textInput.
22 replies
FFilament
Created by Dhaval Kacha on 11/23/2023 in #❓┊help
How to add only edit form to a livewire component.
I have relation like Event has Many Slots Im querying like this.
return $table
->query(Slot::with('event')->where('user_id', Auth::id()))
->columns([])
return $table
->query(Slot::with('event')->where('user_id', Auth::id()))
->columns([])
22 replies
FFilament
Created by Dhaval Kacha on 11/23/2023 in #❓┊help
How to add only edit form to a livewire component.
alright! but sir how to load relationship inside this? i mean Im trying to do like this (event.location): and its not working.
EditAction::make()
->form([
TextInput::make('event.location')
->required()
->maxLength(255),
])
EditAction::make()
->form([
TextInput::make('event.location')
->required()
->maxLength(255),
])
22 replies
FFilament
Created by Dhaval Kacha on 11/23/2023 in #❓┊help
How to add only edit form to a livewire component.
sorry for the tag. so you mean i have to remove this method
public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('reason'),
])
->statePath('data')
->model(Slot::class);
}
public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('reason'),
])
->statePath('data')
->model(Slot::class);
}
and i have to do something like this?
->actions([
EditAction::make()
->form([ TextInput::make('title')
->required()
->maxLength(255),
]),
->actions([
EditAction::make()
->form([ TextInput::make('title')
->required()
->maxLength(255),
]),
22 replies
FFilament
Created by Dhaval Kacha on 11/23/2023 in #❓┊help
How to add only edit form to a livewire component.
@Dan Harrin ?
22 replies
FFilament
Created by Dhaval Kacha on 11/7/2023 in #❓┊help
In AdminPanelProvider I want Plugin (FilamentSpatieRolesPermissionsPlugin) only be loaded for admin.
Solved, all you have to is use policies for both Role and Permission. Inside policies write something like return $user->hasRole('admin');
4 replies