Skip to content

Instantly share code, notes, and snippets.

@Semdevmaster
Created September 21, 2018 11:51
Show Gist options
  • Select an option

  • Save Semdevmaster/4aadf2402e1453dd3b2fe796bf930455 to your computer and use it in GitHub Desktop.

Select an option

Save Semdevmaster/4aadf2402e1453dd3b2fe796bf930455 to your computer and use it in GitHub Desktop.
404 error for api
<?php
//делаем дефолтный роут
Route::fallback(function(){
return response()->json(['message' => 'Not Found.'], 404);
})->name('api404');
// app/Exceptions/Handler.php
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\Route;
public function render($request, Exception $exception)
{
if ($exception instanceof ModelNotFoundException && $request->isJson()) {
return Route::respondWithRoute('api404');
}
return parent::render($request, $exception);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment