Support the ongoing development of Laravel.io →
Requests Eloquent Architecture
Last updated 1 year ago.
0

I'm also curious about this. Here is a quick workaround in the meantime.

$model = User:where('votes', '>', 100)->first();

if (!$model)
{
    abort(500);
}

And then just create a file named 500.blade.php in the resources/views/errors directory. Laravel takes care of the rest. Check out the HTTP Exceptions section of the documentation.

Last updated 9 years ago.
0
Solution

In addition to creating resources/views/errors/500.blade.php, you can catch the ModelNotFoundException in app/Exceptions/Handler.php:

use Illuminate\Database\Eloquent\ModelNotFoundException;
// ...
public function render($request, Exception $e)
{
    if($e instanceOf ModelNotFoundException)
    {
        abort(500);
    }

    return parent::render($request, $e);
}

(I'd do it with a 404 error.)

Last updated 9 years ago.
0

That does the trick!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.