I am trying to make a select from relation. I have the following relation in my Product model:
public function category(){
return $this->belongsTo(Category::class);
}
In my CrudController I describe the field like that:
[
'type' => "relationship",
'name' => 'category', // the method on your model that defines the relationship
],
Like that the select contains all category from db as option, but I need only the ones where user_id
is equal to backpack_user()->id
I've tried to add where clause to relation, and adding the below parameter to the field description array, but no luck so far. Would be nice if someone could show me what I'm missing here.
'options' => (function ($query) {
return $query->where('user_id', backpack_user()->id)->get();
}),