This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
How can I limit the drop down list of a relation field type.
My related model has a column owner_id
so when a new record is created and the dropdown list is rendered, it should only show the items belonging to the user.
Hi,
I would create a scope function like this
public function scopeOwner($query) {
return $query->where('owner_id', 1);
}
And a dropdown list like this:
$list = Model::with(['relations' => function ($q) {
$q->owner();
}])->get();
Regards Crazymodder
Last updated
Will give that a try. Managed to do it by using getModelOptions and build my query there. Though i'm not sure how it works.
Do you have a link to documentation on the scope
function?
A new question, when i update the record and the form is rendered, the selected item isn't showing in the dropdown list. It defaults to the first item. How can i set it to show the saved data?
Dears, i need more explanation on this part, i have a "products" model and i need only to view the products that have the column "is_purchased" set to "1", so i made the scope on the "product" model as follows.
public function scopeRawMaterials($query) { return $query->where('is_purchased', '=', 1); }
so, the question is how do i call this scope in the relation widget?
need urgent help :(
1-8 of 8