请求用户返回null Laravel

I am trying to get the user which is sending the request using this code:

$user = User::where('email', $request['email'])->first();

But it returns null, even though the user is already in the database. Any ideas?

Please try this, Just return or print or echo or anything. But, check with this below code and say what happened.

 public function mailData(Request $request){
   User::where('email', $request->input('email'))->first()
};

I hope this will help you..

The function should be have request and the method will POST or PUT and If you are using GET means you can get email from routes.

public function mailData($email){
   User::where('email', $email)->first()
}

Are you import Model User at the beggining of the file? In the modelfactory php, do you have the User model ?

To get user email from request you should use $requsest->input('email'), after taht your code should be like this,

$user = User::where('email', $request->input('email'))->first();