This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

intosite
intosite

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.

Crazymodder
Crazymodder

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

intosite
intosite

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?

Crazymodder
intosite
intosite

Just tried it and it works. But now it seems like the reorder is breaking.

intosite
intosite

Managed to fixed it. My join statement was causing some conflict in the id columns.

intosite
intosite

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?

atm.it1117342
atm.it1117342

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

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.