You can set up a simple if statement to find out if it's empty by doing...
if ($current->isEmpty()) {
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.
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community