Demon-CZ
Dependent select in attach action
I would like to make dependent select in my attach action. It would depend on the $action->getRecordSelect. How can it be done? Thanks for your answer.
This is my action:
Tables\Actions\AttachAction::make()
->form(fn(Tables\Actions\AttachAction $action): array => [
$action->getRecordSelect(),
Forms\Components\Radio::make('salary_type')->default(SalaryTypeEnum::initial->value)->options([
SalaryTypeEnum::initial->value => 'Mzda dle mzdy v bloku',
SalaryTypeEnum::custom->value => 'Pevna mzda dle hodnoty',
])->label('Druh mzdy')->reactive(),
Forms\Components\TextInput::make('salary')->label(__('Mzda'))->required()->visible(fn(
\Filament\Forms\Get $get
) => $get('salary_type') === SalaryTypeEnum::custom->value),
Select::make('role')
->options(
function(\Filament\Forms\Get $get) {
//HERE I WOULD LIKE TO ADD OPTIONS THAT WILL DEPEND ON USER ID FROM THE GET RECORD SELECT
}
),
Hidden::make('added_by')->default(auth()->id()),
])->modalHeading(__('Priradit instruktora'))->preloadRecordSelect()->recordSelectSearchColumns([
'jmeno',
'prijmeni',
])
})
2 replies
Attach form
I have model of user function, user and event. I have table for user functions, users, events and pivot tables for function_user, function_event and event_instructor(instructor equals user)...In relation manager for users in events I am attaching users to event. In the attach form I have select for user but I would also like to have select for his roles. How can this be achieved? I have tried to add here parts of code but if you need more information about some parts just tell me. Thank you for your help.
InstructorsRelationManager on event
Tables\Actions\AttachAction::make()
->recordSelectSearchColumns(['title', 'description'])
->recordSelectOptionsQuery(fn(Builder $query
) => $query->selectRaw("CONCAT(jmeno,' ', prijmeni) as jmeno, id"))
->label(__('Priradit instruktora'))
->form(fn(Tables\Actions\AttachAction $action): array => [
$action->getRecordSelect(),
**//HERE I NEED TO ADD SELECT FOR THE USER ROLES THAT THE CURRENT USER HAS (its the user that has been selected in the previous select)**
])
Event model
public function instructors(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(User::class, 'event_instructor', 'jednorazovekurzy_id',
'uzivatele_id')->withPivot(['salary', 'salary_type', 'added_by'])->noRegularUsers()->visible();
}
UserFunction Model
public function users(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(User::class, 'user_userfunction', 'user_id', 'userfunction_id');
}
public function events(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Event::class, 'event_userfunction', 'event_id', 'userfunction_id')->withPivot('capacity', 'current_capacity');
}
3 replies
Attach relation manager
Hello, I am little bit confused in relationships. 😅 Can somebody help me with this please?
I have EventResource in it OrganizersRelationManager in it i want to attach and deattach organizers(which has model Customer).
Error: https://flareapp.io/share/o7A9Gqj7
Code OrganizesRelationManager:
class OrganizersRelationManager extends RelationManager
{
protected static string $relationship = 'organizers';
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('name')
->columns([
Tables\Columns\TextColumn::make('name'),
])
->filters([
//
])
->headerActions([
Tables\Actions\AttachAction::make(),
])
->actions([
Tables\Actions\DetachAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DetachBulkAction::make(),
]),
]);
}
}
Relationship in event:
public function organizers()
{
return $this->belongsToMany(Customer::class,'event_organizer', 'event_id', 'customer_id');
}
Relationship in Customer:
public function organizers()
{
return $this->belongsToMany(Event::class,'event_organizer', 'customer_id', 'event_id');
}
2 replies
GetTableQuery
I am trying to get table query on relation manager. I am trying to do this as it is written in docs. But getTableQuery is depricated. How should I do it then? Thanks for answer.
protected function getTableQuery(): Builder
{
return parent::getTableQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
5 replies
Get size of file in file upload
I am trying to get the file size from the upload and then save this value to column called size. Any help please how can it be done? 🥺
error: https://flareapp.io/share/47qKNq0m
Forms\Components\FileUpload::make('path')
->storeFileNamesIn('name')
->directory('projects')
->afterStateUpdated(function (Closure $set, $state) {
$set('size', $state->getSize());
}),
4 replies