relationship and createOptionForm()?


Select::make('companies')
->label('Entreprises autorisées')
->relationship('companies', 'id')
->multiple()
->createOptionForm(function () {
if (Gate::check('create_company') === false) {
return [];
} else {
return CompanyResource::getFormSchema();
}

}
)
->createOptionAction(function (Action $action) {

return $action
->modalHeading('Créer une entreprise')
->modalButton('Créer un entreprise')
->modalWidth('2xl');
})
->createOptionUsing(function ($data) {

return Company::create($data)->id;
})
->disabled(function () {
$result = true;
if (Gate::check('update_users::group') === true) {
$result = false;
}
return $result;
})
->options(Company::all()->pluck('name', 'id'))->searchable(),

Select::make('companies')
->label('Entreprises autorisées')
->relationship('companies', 'id')
->multiple()
->createOptionForm(function () {
if (Gate::check('create_company') === false) {
return [];
} else {
return CompanyResource::getFormSchema();
}

}
)
->createOptionAction(function (Action $action) {

return $action
->modalHeading('Créer une entreprise')
->modalButton('Créer un entreprise')
->modalWidth('2xl');
})
->createOptionUsing(function ($data) {

return Company::create($data)->id;
})
->disabled(function () {
$result = true;
if (Gate::check('update_users::group') === true) {
$result = false;
}
return $result;
})
->options(Company::all()->pluck('name', 'id'))->searchable(),
Error : Call to a member function companies() on null
6 Replies
LeandroFerreira
Is it working?
Select::make('companies')
->label('Entreprises autorisées')
->relationship('companies', 'id')
->multiple()
Select::make('companies')
->label('Entreprises autorisées')
->relationship('companies', 'id')
->multiple()
Becker Maxime
Becker MaximeOP2y ago
No multiple is already present in my code
LeandroFerreira
maybe an issue in your relationship?
Becker Maxime
Becker MaximeOP2y ago
works fine in a createRecord but not in a viewRecord why ?
LeandroFerreira
share the code
Becker Maxime
Becker MaximeOP2y ago
the code is identical in my createRecord
Want results from more Discord servers?
Add your server