This is my controller:
return View::make('home.listings')
->with('listings', Listing::all());
Previously, I checked it on views like this: (and it worked on all my projects)
@if(!empty($listings))
//use foreach and show listings
@else
<h3>No listing is found.</h3>
@endif
This is my Listing model.
class Listing extends Eloquent {
public static $key = 'id';
protected $table = 'ilanlar';
public $timestamps = false;
}
Right now, it works when there is an entry in database. However, when there is not, it doesn't get to the else block. Because:
dd(!empty($listings)) //output: (boolean) true
And, when I output listings variable:
dd($listings) //outputs:
object(Illuminate\Database\Eloquent\Collection)[229]
protected 'items' =>
array (size=0)
empty
This is the reason why it doesn't reach else block, because Eloquent returns and object and it casts to true.
The problem is: I don't know why it returns an Eloquent collection. Previously it didn't. Am I overlooking something?