Call to a member function isEmpty() on a non-object?
laravel, laravel-4
Solution
`isEmpty()` is a Collection method. For some weird reasons, in views, it sometimes refer to an empty Collection as `null`. The safest check, in my opinion would be to do a counts check, like so:
if (count($data)) {...}
This works well both in Controllers and Views.
Problem
I make my view in the controller via: ``` $data = Lib::index(); $view = View::make('index') ->with('data', $data) ->render(); return $view; ``` I can check if data is empty in the controller via: ``` $data->isEmpty(); ``` But when I try the same thing in the view I get the error: ``` Call to a member function isEmpty() on a non-object ``` Why? Here's the code for Lib::index(): ``` $page = isset($_GET['page']) ? ($_GET['page']) : 1; Paginator::setCurrentPage($page); try { $data = Asset::with(array('sizes'=> function($query){ $query->select('width', 'height', 'asset_id'); }))->where('active', 1)->orderBy('updated_at', 'DESC')->paginate(Config::get('p.results_per_page'), array('id', 'alt')); } catch (QueryException $e) { App::abort(404); } return $data; ```