简体   繁体   中英

Request user return 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 ?

要从请求中获取用户电子邮件,您应该使用$requsest->input('email') ,之后代码应该像这样,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM