riz
riz
FFilament
Created by riz on 1/6/2024 in #❓┊help
Can't use FileUpload with multiple
I have a resource form with FileUpload. FileUpload works fine with out using the "multiple". But when using multiple I get this error: Illuminate\Database\Grammar::parameterize(): Argument #1 ($values) must be of type array, int given, EMPLOYEE Model
protected $casts = [
'attachment_path' => 'array',
];

public function attachment() : HasOne
{
return $this->hasOne(Attachment::class, 'group_id');
}
protected $casts = [
'attachment_path' => 'array',
];

public function attachment() : HasOne
{
return $this->hasOne(Attachment::class, 'group_id');
}
Employee Resource
Forms\Components\Section::make()
->relationship(
'attachment',
condition: fn (?array $state): bool => filled($state['attachment_path']),
)
->schema([
Forms\Components\FileUpload::make('attachment_path')
->multiple()
->openable(),
])
Forms\Components\Section::make()
->relationship(
'attachment',
condition: fn (?array $state): bool => filled($state['attachment_path']),
)
->schema([
Forms\Components\FileUpload::make('attachment_path')
->multiple()
->openable(),
])
4 replies
FFilament
Created by riz on 12/11/2023 in #❓┊help
How to check if Fileupload is filled
How to check a fileupload component is filled, like in the code below I want to enable the toggle component only when textinput and fileupload is filled.. I tried $get('attachments') to no avail
Forms\Components\TextInput::make('first_name'),

Forms\Components\FileUpload::make('attachments')
->multiple(),

Forms\Components\Toggle::make('is_toggled')
->onIcon('heroicon-m-user')
->offIcon('heroicon-m-user')
->onColor('success')
->offColor('')
->dehydrated()
->disabled(fn (Get $get) => $get('first_name') === null)
Forms\Components\TextInput::make('first_name'),

Forms\Components\FileUpload::make('attachments')
->multiple(),

Forms\Components\Toggle::make('is_toggled')
->onIcon('heroicon-m-user')
->offIcon('heroicon-m-user')
->onColor('success')
->offColor('')
->dehydrated()
->disabled(fn (Get $get) => $get('first_name') === null)
3 replies
FFilament
Created by riz on 10/20/2023 in #❓┊help
afterCreate() function can't get the last saved record id, dd() show the error below:
ERROR: "SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'approvable_id' cannot be null (Connection: mysql, SQL: insert into approval (status, approvable_id, approvable_type, updated_at, created_at) values (Pending, ?, App\Models\Applicant, 2023-10-20 10:35:02, 2023-10-20 10:35:02)) ◀" // app\Filament\Resources\ApplicantResource\Pages\CreateApplicant.php:27 protected function afterCreate(): void {
try {
$this->record->approval()->create(['status' => 'Pending']);
} catch (\Throwable $th) { dd($th->getMessage()); //$this->record->forceDelete(); } }
8 replies
FFilament
Created by riz on 10/18/2023 in #❓┊help
afterCreate in AttachAction
award Model belongstomany nominees return $this->belongsToMany( Employee::class, 'award_nominees', 'award_id', 'empl_id'
)->withTimestamps() ->withPivot(['nominated_by', 'remarks']);
------------------- nominee Model
belongsto award belongsto employee approval()-morphmany return $this->morphMany(ApprovalWorkflow::class, 'approvable');
latestApproval() : MorphOne return $this->morphOne(ApprovalWorkflow::class, 'approvable')->latestOfMany(); ----------------------
employee Model belongstomany awards ----------------------------- I can save the data in 'award_nominees' table in my NomineeResource.php and in my NomineeResource\Pages\CreateNominee.php and I can initialize the 'status' = 'Pending' on the Morph table using this line
function afterCreate() try { $this->record->approval()->create(['status' => 'Pending']); } catch (\Throwable $th) { $this->record->forceDelete(); }
now in my AwardResource I have a RM NomineesRelationManager.php and I use AttachAction to submit a nominee data and save to the database, it can save the data that I want in the table "award_nominees", but how can I initialize the 'status' in my morph table like in my NomieeResource, using afterCreate(), how can i do that? in my NomineesRelationManager.php protected static string $relationship = 'nominees'; ->headerActions([
AttachAction::make() ->using(function (Model $record) {dd($record);}), dd output is App\Models\Employee it should have been Models\Nominee so I could initialize the status like this approval()->create(['status' => 'Pending']);
2 replies
FFilament
Created by riz on 10/11/2023 in #❓┊help
Assign default value on a field during AttachAction
In my RM form if I want to attach an employee, it will ask to select a status, what I want to do is when I attach an employee it will not ask to select for 'status' but rather set the 'status' to 'Pending' by default. AttachAction::make()
->label('Assign Employee') ->form(fn (AttachAction $action): array => [
Section::make() ->schema([ Select::make('recordId') ->options(Employee::all()->pluck('full_name', 'empl_id')) ->label('Employee') ->searchable() ->preload() ->multiple(), TextInput::make('assigned_by'), Select::make('status') ->options([ 'approve' => 'Approve', 'disapprove' => 'Disapprove', 'pending' => 'Pending', 'on-process' => 'On process', ])->required(),
]),
])
7 replies