常规错误:1364字段“ user_id”没有默认值,使用其他防护登录后如何存储user_id

时间:2018-10-18 13:06:37

标签: php laravel laravel-blade

我有两种类型的默认值守卫和一个称为客户的守卫。我试图让客户关注用户,但出现错误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  

0 个答案:

没有答案