Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

You can set up a simple if statement to find out if it's empty by doing...

if ($current->isEmpty()) {
Last updated 9 years ago.
0

Following should work if you want to use try/catch

use Illuminate\Database\Eloquent\ModelNotFoundException;
...
try {
  $current = Promovote::where('module_id',$data['module'])->firstOrFail($id);
} catch (ModelNotFoundException $ex) {
  // Error handling code
}

Rewritten from some of my Laravel 5.1 code.

EDIT: This assumes you expect zero or one record, not multiple.

Last updated 9 years ago.
0

You can edit your app/Exceptions/Handler.php file by specifying a way to render certain exceptions.

public function render($request, Exception $e)
{
    if ($e instanceof ModelNotFoundException) {
        return response()->view('errors.custom', [], 500);
    }

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

Check documentation, Errors Section.

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

CrowdForge crowdforge Joined 18 Aug 2015

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.