Laravel Checking If a Record Exists

后端 未结 26 2340
礼貌的吻别
礼貌的吻别 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:14

    Laravel 5.6.26v

    to find the existing record through primary key ( email or id )

        $user = DB::table('users')->where('email',$email)->first();
    

    then

          if(!$user){
                 //user is not found 
          }
          if($user){
                 // user found 
          }
    

    include " use DB " and table name user become plural using the above query like user to users

提交回复
热议问题