why can not find a user with that e-mail address?

前端 未结 4 754
耶瑟儿~
耶瑟儿~ 2021-01-27 09:46
public function create(Request $request) { 
    $this->validate($request, [ \'email\' => \'required|email\', ]);
    $user          


        
4条回答
  •  南笙
    南笙 (楼主)
    2021-01-27 10:25

    Try with isEmpty(), Like this :

    public function create(Request $request) { 
        
        $validatedData = $request->validate([
            'email' => 'required|email',
        ]);
    
        $user = User::where('email', $request->email)->first();
    
        if ($user->isEmpty())  {
            return response()->json([
                 'message' => 'We can not find a user with that e-mail address.' 
            ], 404);
         } else {
              return response()->json([
                 'message' => 'User is found'], 201 );
         }
    }
    

提交回复
热议问题