Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

davy_yg's avatar
Level 27

API login

Hello,

I create api for login that returns username and message retrieved user successfully:

public function index(Request $request)
{
 
    $data = $request->all();
    $data['email'] = $request->email;
    $password = bcrypt($request->password);

    $User = User::where('email', $data['email']) and where('password', $password)->get();

    if($User != null){

        return $this->sendResponse($data->toArray(), 'Users retrieved successfully');    
    }
    
   }

I am not sure if I write this line correctly:

$User = User::where('email', $data['email']) and where('password', $password)->get();

please help me correct it?

0 likes
1 reply
siangboon's avatar

why not you run it and let us know the result?

1 like

Please or to participate in this conversation.