I am spinning up a application in Laravel 5 and I am relatively new to the framework. I am manually authenticating a user and the question I'm asking could be across the framework. I am checking if the user's credentials are correct, by querying the database and using a firstOrFail. I was wondering if there are any advantages to using a try/catch and catching the error or checking if empty?
try {
User::where('email', $request->email)->where('password', $request->password)->firstOrFail();
} catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
// Display error
}
versus
$user = User::where('email', $request->email)->where('password', $request->password)->first();
if (empty($user)) {
// Display error
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire