Laravel 版本:5.8
Laravel 管理员:1.7.9
我无法进行级联选择
我有桌子:
用户:身份证、姓名
类别:身份证、姓名
categories_users: id, categories_id, user_id
楷模:
class User extends Authenticatable {
public function category()
{
return $this->belongsToMany(Categories::class, 'categories_users', 'categories_id');
}
}
class Categories extends Model {
public function users()
{
return $this->belongsToMany(User::class, 'categories_users');
}
}
我需要级联选择:
$form->select('user_id', 'User')->options($seller)->load('categories_id', '/admin/api/users')->required();
$form->select('categories_id', 'Categories of user')->required();
但它不起作用!
控制器:
public function getData(Request $request){
$user_id = $request->get('q');
return User::find($user_id)->category()->get(['id', DB::raw('name as text')]);
}