vendredi 17 mars 2017

How to use Laravel elequent model to get data with mutiple where condition

I am new to Laravel and currently working on Laravel 5.1. I am trying to authenticate user by its email and password. To get this, I am using the below code to find the user:

First Method: Using Elequent Model

$result = user_model::where('email', $data['email'])->where('password', \Illuminate\Support\Facades\Hash::make($data['password']))->first();  

Second Method: Using with() Method:

$result = user_model::where('email', $data['email'])
        ->where(function($q) use($data) {
            $q->where('password', '=', Hash::make($data['password']));
        })->first();  

Third Method: Using query Builder:

$result = DB::table('users')->where('email', $data['email'])->where('password', Hash::make($data['password']))->get();  

Each of the above method is returning null even the the user is exist into database.

If I use single where condition either for email or password then First method returns user object with data.

Can anyone help me for How can i get the result of query having multiple where conditions.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire