Closed xoco70 closed 3 years ago
Hi,
I have 2 dependants fields: Company and Operations. An Operation belongsTo a Company.
I also have 2 user roles, SuperUser, and SimpleUser. SuperUser can see all companies, while simpleUser belongsTo a company
So, I have a local scope in Company model:
/** * @param Builder $query * @return Builder */ public function scopeMines($query) { if (auth()->user()->isSuperAdmin()) { return $query; } return $query->where('company_id', auth()->user()->company_id); }
I use it in Resource:
NovaBelongsToDepend::make('Structure', 'company', \App\Nova\Company::class) ->options(\App\Models\Company::mines()) ->rules('required');
I also tried to put the query directly in ->options() but got no luck:
->options()
$structure = NovaBelongsToDepend::make('Structure', 'company', \App\Nova\Company::class) ->options(function () { return \App\Models\Company::all(); // gives empty list }) ->rules('required');
But it gives me a empty list.
A better thing for me should be to completely hide it, with ->hideWhenCreating()->hideWhenUpdating() but then I can't pass the value of company to child select
->hideWhenCreating()->hideWhenUpdating()
My bad, had to use ->get()
NovaBelongsToDepend::make('Structure', 'company', \App\Nova\Company::class) ->options(\App\Models\Company::mines()->get()) ->rules('required');
Hi,
I have 2 dependants fields: Company and Operations. An Operation belongsTo a Company.
I also have 2 user roles, SuperUser, and SimpleUser. SuperUser can see all companies, while simpleUser belongsTo a company
So, I have a local scope in Company model:
I use it in Resource:
I also tried to put the query directly in
->options()
but got no luck:But it gives me a empty list.
A better thing for me should be to completely hide it, with
->hideWhenCreating()->hideWhenUpdating()
but then I can't pass the value of company to child select