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?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire