Based on your edited question, if you use take()
the returned object would be a Illuminate\Database\Eloquent\Collection
, instead of Illuminate\Database\Eloquent\Model
, even if the returned collection has one model object, or none (in that case, an empty collection will be returned).
Instead, you can use find()
and get a model object using the primary key, or add first()
to your query to get the first result from the query as a model object. These two methods will return null
if the query does not match an entry.
For example:
$user = User::find(1);
Output:
{
"error":"true",
"message":"User exists.",
"user":false,
"usertype":"object",
"usercontent":{
"timestamps":true,
"autoHashPasswordAttributes":true,
"validationErrors":{},
"throwOnValidation":false,
"autoHydrateEntityFromInput":false,
"forceEntityHydrationFromInput":false,
"autoPurgeRedundantAttributes":false,
"incrementing":true,
"exists":true
}
}
$user = User::find(483);
Output: empty
For your specific query, you can modify it as the following code to make it work:
$user = User::where('mobile_number', '=', Request::get('mobile_number'))
->orwhere('email_id', '=', Request::get('email_id'))
->first()