dimanche 31 mars 2019

How to throw exception if no data Laravel?

How to throw exception if no data Laravel when I expect some values?

$roles = Auth::user()->roles()->get();

So, is it good idea to use:

if ($roles->count() == 0) {
   throw new \Exception('No data');
}

But what if $roles are null?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2FFNCjH
via IFTTT

Aucun commentaire:

Enregistrer un commentaire