Thursday, March 16, 2017

How to return empty list of records in laravel?

I have some model Task.

If current user has permission then he can see all tasks

return Task::all();

If current user does not have this permission then he can see only empty list

return Task::where('id', 0)->get();

Design is so that user must always get some result, but my functions work with data returned from Task::all() so I can not return empty array or empty Eloquent collection.

What should I do?



via Jackson J

Advertisement