我有一个方法可以检查角色是否等于 1,然后发回一些数据。该方法看起来像这样:
if($user->role == 1) {
$dmca = Dmca::get()->take(5);
$data = [
'status' => 200,
'data' => $dmca
];
return response($data);
} else {
$dmca = Dmca::where('client', $request->user_id)->get()->take(5);
$data = [
'status' => 200,
'data' => $dmca
];
return response($data);
}
}
在 $user 实例的转储和死亡中,您可以看到角色存在并已设置。但返回时,我收到错误
#attributes: array:11 [
"id" => 1
"name" => null
"email" => "Grahammorbydev@gmail.com"
"model_name" => "man"
"subscribed" => 0
"email_verified_at" => null
"password" => "$2y$10$yy1Yj.GGez7efEdFdkjaf.RlQS17Zc7QYUANz3RvdE00fVm0f9AYq"
"role" => 1
"remember_token" => null
"created_at" => "2020-07-05 17:54:38"
"updated_at" => "2020-07-05 17:54:38"
]
axios返回时出现以下错误
"Property [role] does not exist on this collection instance."
慕田峪7331174