使用此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);
}
但它不起作用!! 感谢
答案 0 :(得分:0)
我在问题中建议的链接中找到了答案。
在 @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).