riz
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
Employee Resource
4 replies
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
try {
$this->record->approval()->create(['status' => 'Pending']);
} catch (\Throwable $th) { dd($th->getMessage()); //$this->record->forceDelete(); } }
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
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']);
)->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
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(),
]),
])
->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