Reputation: 399
I have the following query which works:
$results = TransactionModel::take(5)->skip(5)->get();
this returns eloquent objects plus the result array.
$results = TransactionModel::find(1);
where 1 is just an example when i try 11 it returns a result.
My question is:
If the key is not found by the Model then why does it not return Eloquent object with an empty array. The result I get is absolutely nothing.
isset($results)
should always return true because it has default eloquent objects but mine is returning false?
so the attributes array should be:
[attributes:protected] => Array()
but the actual variable $results doesn't exist at all.
Upvotes: 0
Views: 320
Reputation: 81
Eloquent does not return an array because it would be unnecessary to return an array for a single object. It also prevents you from having to specify and array index for the object to access it, and since it returns false if there are no results, you do not have to check if the result array is empty if you have no results.
Upvotes: 0