F
Filament14mo ago
riz

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']);
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server