Laravel-admin: How to apply Tree model query under selectOptions()

Created on 28 Feb 2017  路  2Comments  路  Source: z-song/laravel-admin

Tree model query works fine:

            $tree->query(function ($model) use($productid) {
                return $model->where('user_id', Auth::guard('admin')->user()->id);
            });

How to apply same query under:

$form->select('parent_id','Parent')->options(Document::selectOptions());

Most helpful comment

No it's not working, I have created my own function under the model to resolve this issue:

    public static function selectedOptions()
    {
        $options = Document::where('user_id', Auth::guard('admin')->user()->id)->orderby('order')->get()->toArray();
        if (!empty($options))
            $options = (new static())->buildSelectOptions($options);

        return collect($options)->prepend('Root',0)->all();
    }

All 2 comments

Try Document::where('user_id', Admin::user()->id)->selectOptions()

No it's not working, I have created my own function under the model to resolve this issue:

    public static function selectedOptions()
    {
        $options = Document::where('user_id', Auth::guard('admin')->user()->id)->orderby('order')->get()->toArray();
        if (!empty($options))
            $options = (new static())->buildSelectOptions($options);

        return collect($options)->prepend('Root',0)->all();
    }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

greentornado picture greentornado  路  3Comments

evans-kim picture evans-kim  路  3Comments

benny-sun picture benny-sun  路  3Comments

qcol picture qcol  路  3Comments

MarKco picture MarKco  路  3Comments