problem createOptionForm()

my code works in my resource :
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(),
14 Replies
Becker Maxime
Becker MaximeOP2y ago
but not in my widget :
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(),
yet my code is identical why ?
Patrick Boivin
What is the issue exactly?
Becker Maxime
Becker MaximeOP2y ago
the problem is that I can create a company in the createRecord but not in my page I get this error
Becker Maxime
Becker MaximeOP2y ago
Patrick Boivin
Can you share the code of your widget / custom form?
Patrick Boivin
Can you click on the SHARE button on this screen and share the link?
Becker Maxime
Becker MaximeOP2y ago
I didn't understand, what do you want?
LeandroFerreira
$this->record is null.. where are you initializing this? Did you check the $this->record->companies() output?
Becker Maxime
Becker MaximeOP2y ago
the widget is in a viewRecord page, I get the record this way, and when I display the variable(dd($this->record->companies()) in my mount function I get something back
Patrick Boivin
In your screenshot that shows the Call to a member function... error, there's a SHARE button. Can you click it and share the link?
Becker Maxime
Becker MaximeOP2y ago
https://flareapp.io/share/x7KlzxB5, thank you for your tip I did not know it
Patrick Boivin
I think you're missing a connection between the model and the form... the Select doesn't know what to do with ->relationship()
Want results from more Discord servers?
Add your server