Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Dosmukhanbet's avatar

Filamentphp - access parent method from Resource

hi, can someone help with following issue, there is RequisitionResource with infolist method for the "department.approvers" relationship , having issue to call one of parent model method, can anybody advise how to call parent instance inside RepeatableEntry

class RequisitionResource extends Resource
{
    protected static ?string $model = Requisition::class;

    protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';


    public static function form(Form $form): Form
    {
    
    }

    public static function table(Table $table): Table
    {
      
    }

    public static function getRelations(): array
    {
        return [
            ItemsRelationManager::class,
        ];
    }

    

    public static function infolist(Infolist $infolist): Infolist
    {
        // dd($infolist->record->isApprovedBy(Auth::user()));
        return $infolist
            ->schema([
              
                    Components\Section::make('Requisition Approvers')
                        ->schema([
                            RepeatableEntry::make('department.approvers')
                                    ->label('Department Approvers')
                                    ->schema([
                                                TextEntry::make('fullName')->label('Name'),
                                                TextEntry::make('id')
                                                ->state(function (Model $record) {
													//here need to call parent model method
													//    ->isApprovedBy($record)
                                                    return $record->id;
                                                })
                                            ])
                                            ->columns(2)
                                ])
                                ->columns(4)
                                ->collapsible(),

                    ]);

    }

class Requisition extends Model
{
    use HasFactory;

    public function department()
    {
        return $this->belongsTo(Department::class);
    }

    /** return Approved users */
    public function approvals()
    {
        return $this->belongsToMany(User::class, 'requisition_approvals','requisition_id','user_id')->withTimestamps()->withPivot('approved', 'comments', 'created_at');
    }

    public function isApprovedBy(User $user)
    {
        return $this->approvals->contains($user);
    }



}

0 likes
0 replies

Please or to participate in this conversation.