handle MethodNotAllowedHttpException laravel


buka /app/Exceptions/Handler

tambahkan kode ini atas , use Symfony \ Component \ HttpKernel \ Exception \
MethodNotAllowedHttpException

kemudian

public function render($request, Exception $exception)
{
//tambahkan kode ini

if ($exception instanceof MethodNotAllowedHttpException) {
//jika ajax
if($request->ajax())
{

return response()->json([‘error’ => ‘halaman tidak ditemukan’],401);
}

//jika nonajax
return redirect(‘/home’)->with([‘warning’ => ‘halaman tidak ditemukan’ ]);
}

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

referensi
https://laracasts.com/discuss/channels/laravel/best-way-to-handle-methodnotallowedhttpexception?page=1
https://laravel.com/docs/5.8/errors
https://github.com/getsentry/sentry-laravel/issues/246

Ditulis dalam php. Leave a Comment »

tinggalkan pesan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d blogger menyukai ini: