mgsmus Hepinize çok teşekkür ederim. Ama Sonuç doğru ise dd ile bir veri yakalayabiliyorum. girdiğim api linki yok ise middleware uğramıyor veya Handler da yakalayamıyorum bu kısmı.
Eklediğim şekil şöyle.
Middleware Dosyası
<?php
namespace App\Http\Middleware;
use Closure;
class ApiNotFoundJson
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$request->headers
->set('Accept', 'application/json');
return $next($request);
}
}
Kernel Dosyası
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\LocaleMiddleware::class,
// \App\Http\Middleware\SupplierMiddleware::class
],
'api' => [
ApiNotFoundJson::class,
'throttle:500,1',
'bindings',
// \App\Http\Middleware\AccountType::class
],
'admin' => [
'auth',
'password_expires',
'permission:view backend',
],
'sessions' => [
\Illuminate\Session\Middleware\StartSession::class,
]
];
Handler Dosyası
public function render($request, Exception $exception)
{
if ($exception instanceof NotFoundHttpException && $request->expectsJson()) {
return response()->json([
'status' => 0,
'message' => __('404 mesajınız hard coded yada dile bağımlı'),
'data' => []
], 404);
}
if ($exception instanceof UnauthorizedException) {
return redirect()
->route(home_route())
->withFlashDanger(__('auth.general_error'));
}
return parent::render($request, $exception);
}