Laravel Checking If a Record Exists

后端 未结 26 2279
礼貌的吻别
礼貌的吻别 2020-11-28 17:50

I am new to Laravel. Please excuse the newbie question but how do I find if a record exists?

$user = User::where(\'em         


        
26条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 18:07

    In your Controller

    $this->validate($request, [
            'email' => 'required|unique:user|email',
        ]); 
    

    In your View - Display Already Exist Message

    @if (count($errors) > 0)
        
      @foreach ($errors->all() as $error)
    • {{ $error }}
    • @endforeach
    @endif

提交回复
热议问题