Emil | Emien
Emil | Emien
FFilament
Created by Emil | Emien on 9/11/2023 in #❓┊help
Multi tenancy - Select relationship() - Searchable() remove tenant information when clicked
Forms\Components\Select::make('client_id')
->relationship('client', 'name')
->required()
->searchable()
->preload()
->noSearchResultsMessage(__('No client found'))
->createOptionForm([
Forms\Components\TextInput::make('name')
->required(),
Forms\Components\TextInput::make('phone')
->tel(),
Forms\Components\TextInput::make('email')
->email(),
]),
Forms\Components\Select::make('client_id')
->relationship('client', 'name')
->required()
->searchable()
->preload()
->noSearchResultsMessage(__('No client found'))
->createOptionForm([
Forms\Components\TextInput::make('name')
->required(),
Forms\Components\TextInput::make('phone')
->tel(),
Forms\Components\TextInput::make('email')
->email(),
]),
When I load the page, this query is run
select `clients`.`name`, `clients`.`id` from `clients` where `clients`.`company_id` in (1) order by `clients`.`name` asc
select `clients`.`name`, `clients`.`id` from `clients` where `clients`.`company_id` in (1) order by `clients`.`name` asc
But as soon as I click the select-input, it runs this query and load all the clients
select `clients`.`name`, `clients`.`id` from `clients` order by `clients`.`name` asc
select `clients`.`name`, `clients`.`id` from `clients` order by `clients`.`name` asc
The same happens when I click the "create" button. Is the only way to use options(), and remove the option to create a new client from that page? Or have I missed something in the docs?
Forms\Components\Select::make('client_id')
// ->relationship('client', 'name')
->options(Client::all()->pluck('name','id')) // Custom Middleware add whereBelongs()
->required()
->searchable()
->preload()
->noSearchResultsMessage(__('No client found')),
Forms\Components\Select::make('client_id')
// ->relationship('client', 'name')
->options(Client::all()->pluck('name','id')) // Custom Middleware add whereBelongs()
->required()
->searchable()
->preload()
->noSearchResultsMessage(__('No client found')),
On the last example, this query is run everytime:
select * from `clients` where `clients`.`company_id` in (1)
select * from `clients` where `clients`.`company_id` in (1)
5 replies