我有两种类型的默认值守卫和一个称为客户的守卫。我试图让客户关注用户,但出现错误General error: 1364 Field 'user_id' doesn't have a default value
。我知道为什么,但我不知道如何解决该问题。如果我使用客户保护工具进行签名,那么当我没有使用默认用户保护工具进行登录时,如何从用户页面中获取user_id。
控制器:
public function follow(User $user, $slug) {
$user = User::where('slug', $slug)->first();
$customer = Auth::guard('customer')->user();
$customer->follow($user);
return redirect()->back()->with('success', 'You are now following user');
}
public function unfollow(User $user, $slug){
$merchant = User::where('slug', $slug)->first();
$customer = Auth::guard('customer')->user();
$customer->unfollow($merchant);
return redirect()->back()->with('success', 'You have unfollowed merchant');
}
查看:
@if(Auth::guard('customer')->user())
@if(Auth::guard('customer')->user()->isfollowing($user))
<a href="{{ url('account/'.$user->slug.'/unfollow') }}" class="btn btn-danger">Unfollow</a>
@else
<a href="{{ url('account/'.$user->slug.'/follow') }}" class="btn btn-success">Follow</a>
@endif
@endif