F
Filamentβ€’17mo ago
sanis

Select of relationship gives "call on null"

Hello, I'm building pretty simple case for an admin panel where Ingredient BelongsTo Menu, so basically I have created an actions EditIngridient and CreateIngridient which returns form of couple fields. One of them is relation of menu. However on edit page/create page I'm getting an error Call to a member function menu() on null. This is my Ingredient descriptions: https://gist.github.com/sanis/c8e0c0a28acd2892c5a3db70a18bc1e3 And this is flare errors: https://flareapp.io/share/4m4BV1Z7 https://flareapp.io/share/VmeMWnzm Any ideas how to fix it and why this is happening? Using filament beta 9.
Gist
Ingredients and menu relation
Ingredients and menu relation. GitHub Gist: instantly share code, notes, and snippets.
Flare
Call to a member function menu() on null - The error occurred at http://localhost/admin/ingredients/create
Flare
Call to a member function menu() on null - The error occurred at http://localhost/admin/ingredients/99b34c20-9228-4b41-8b67-80cf2969bc59/edit
Solution:
Made a quick change and this did the trick (calling parent::form($form) on Page form: `return parent::form($form) ->schema(...
Jump to solution
5 Replies
Solution
sanis
sanisβ€’17mo ago
Made a quick change and this did the trick (calling parent::form($form) on Page form: return parent::form($form) ->schema( [ TextInput::make('code'), Select::make('menu_uuid')->relationship(name: 'menu', titleAttribute: 'code') ] );
Dennis Koch
Dennis Kochβ€’17mo ago
On the original form there are other configurations like ->statePath() which maps the data to $data property. That's why your form broke.
sanis
sanisOPβ€’17mo ago
Okay, makes sense.
public function form(Form $form): Form
{
return
$form
->model($this->getRecord())
->statePath($this->getFormStatePath())
->schema(
[
TextInput::make('code'),
Select::make('menu_uuid')->relationship(name: 'menu', titleAttribute: 'code')
]
);
}
public function form(Form $form): Form
{
return
$form
->model($this->getRecord())
->statePath($this->getFormStatePath())
->schema(
[
TextInput::make('code'),
Select::make('menu_uuid')->relationship(name: 'menu', titleAttribute: 'code')
]
);
}
makes it work. However this wasn't a problem on v2 right?
Dennis Koch
Dennis Kochβ€’17mo ago
This worked the same way in v2 Oh maybe there was some change, because the form/table syntax is new
sanis
sanisOPβ€’17mo ago
it must have been change because it was working before the weekend and now after the weekend (during the weekend I did the upgrade) it's like this :/ Anyhow, there is a solution, but it would be nice to have on the docs as well πŸ™‚ Thanks for your input !
Want results from more Discord servers?
Add your server