Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing 'findByUuidOrFail' method #5

Open
majidalaeinia opened this issue Jun 18, 2019 · 1 comment
Open

Implementing 'findByUuidOrFail' method #5

majidalaeinia opened this issue Jun 18, 2019 · 1 comment

Comments

@majidalaeinia
Copy link

As you might have read on Laravel Documentation:

Sometimes you may wish to throw an exception if a model is not found. This is particularly useful in routes or controllers. The findOrFail and firstOrFail methods will retrieve the first result of the query; however, if no result is found, a Illuminate\Database\Eloquent\ModelNotFoundException will be thrown:

$model = App\Flight::findOrFail(1);

$model = App\Flight::where('legs', '>', 100)->firstOrFail();$model = App\Flight::findOrFail(1);

$model = App\Flight::where('legs', '>', 100)->firstOrFail();

If the exception is not caught, a 404 HTTP response is automatically sent back to the user. It is not necessary to write explicit checks to return 404 responses when using these methods:

Route::get('/api/flights/{id}', function ($id) {
    return App\Flight::findOrFail($id);
});

It would be nice if we had the equivalent findByUuidOrFail method.

@majidalaeinia majidalaeinia changed the title Implementing findByUuidOrFail Implementing findByUuidOrFail method Jun 18, 2019
@majidalaeinia majidalaeinia changed the title Implementing findByUuidOrFail method Implementing 'findByUuidOrFail' method Jun 18, 2019
@kilrizzy
Copy link
Contributor

Agreed this would be a really nice feature. I can add in when I have time but if anyone wants to PR I'm open to using

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants