Laravel 背包 addField where 子句

Laravel backpack addField where clause

使用这个link

我尝试在 addField 中添加一个 where 子句,只有当它们符合条件时,下拉列表才应将内容作为选项加载。

代码如下:

$this->crud->addField([ // select_from_array
        'name' => 'manager',
        'label' => "Manager Name",
        'type' => 'select_callback', // Custom field type of select2
        'entity' => 'Manager',
        'attribute' => 'name',
        'model' => 'App\Models\Manager',
        'scope' => 'manager'
        // 'allows_multiple' => true, // OPTIONAL; needs you to cast this to array in your model;
    ], 'update/create/both'); 

并且在Model.php

public function scopeManager($query)
{
    return $query->where('gym_code', Auth::user()->gym_code);
}

但是没有用!! 谢谢

我在问题中建议的 link 中找到了答案。

在link@thplat回答了一个变化在select_callback.blade.php

For the select_callback view I took the select view and changed only one line there. We go from: @foreach ($field['model']::all() as $connected_entity_entry) to @foreach ((isset($field['callback']) ? $field['callback']() : $field['model']::all()) as $connected_entity_entry).