{"id":11352,"date":"2023-02-20T07:00:10","date_gmt":"2023-02-19T22:00:10","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=11352"},"modified":"2023-01-30T02:35:41","modified_gmt":"2023-01-29T17:35:41","slug":"%e3%80%90laravel-react%e3%80%91%e7%8b%ac%e8%87%aa%e3%81%ae-exception-%e3%81%a7%e6%93%ac%e4%bc%bc%e7%9a%84%e3%81%aa%e3%83%90%e3%83%aa%e3%83%87%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%82%92%e3%81%99","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=11352","title":{"rendered":"\u3010Laravel +  React\u3011\u72ec\u81ea\u306e Exception \u3067\u64ec\u4f3c\u7684\u306a\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u3059\u308b"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u79c1\u306f<code>Laravel 4.2<\/code>\u304b\u3089<code>Lover<\/code>\u306a\u306e\u3067\u3059\u304c\u3001\u305d\u308c\u304b\u3089\uff17\u5e74\u3050\u3089\u3044\u305f\u3063\u305f\u3044\u307e\u3067\u3082\u300c<strong>\u3048\uff01\u305d\u3093\u306a\u6a5f\u80fd\u3042\u3063\u305f\u306e\uff01\uff1f<\/strong>\u300d\u3068\u3044\u3046\u3082\u306e\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u7279\u306b<code>Laravel<\/code>\u306f\u30de\u30a4\u30ca\u30fc\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3067\u3082\u30ac\u30f3\u30ac\u30f3\u65b0\u6a5f\u80fd\u3092\u8ffd\u52a0\u3057\u3066\u304d\u305f\u308a\u3059\u308b\u306e\u3067\u3001\u591a\u3059\u304e\u3066\u3059\u3079\u3066\u30ad\u30e3\u30c3\u30c1\u30a2\u30c3\u30d7\u3059\u308b\u306e\u306f\u96e3\u3057\u3044\u3093\u3067\u3059\u3088\u306d\u3002\uff08\u305d\u306e\u5206\u3001\u8abf\u3079\u305f\u3089\u307b\u307c\u4f55\u3067\u3082\u3067\u304d\u3061\u3083\u3046\u306e\u304c\u9b45\u529b\u3067\u3059\ud83d\udc4d\uff09<\/p>\n<p>\u305d\u3057\u3066\u3001\u5148\u65e5\u767a\u898b\u3057\u305f\u306e\u304c\u3001\u4eca\u56de\u306e\u30c6\u30fc\u30de<\/p>\n<p><strong style=\"font-size: 35px;\">\u72ec\u81ea\u306e Exception\uff08\u4f8b\u5916\uff09<\/strong><\/p>\n<p>\u3067\u3059\u3002<\/p>\n<p>\u306a\u3093\u3068\u3001<code>Laravel<\/code>\u306b\u306f<code>php artisan make:exception<\/code>\u3068\u3044\u3046\u72ec\u81ea\u306e\u4f8b\u5916\u3092\u4f5c\u6210\u3059\u308b\u30b3\u30de\u30f3\u30c9\u304c\u3042\u308b\u3093\u3067\u3059\u304c\u3001\u3069\u3046\u3084\u3089\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u3082\u3053\u306e\u30b3\u30de\u30f3\u30c9\u81ea\u4f53\u306f\u8f09\u3063\u3066\u3044\u306a\u3044\u3088\u3046\u306a\u3093\u3067\u3059\u306d\uff082022.12.26\u73fe\u5728\uff09<\/p>\n<p>\u305d\u3053\u3067\u2757<\/p>\n<p>\u4eca\u56de\u306f\u72ec\u81ea\u306e<code>Exception<\/code>\u3092\u3064\u304f\u3063\u3066\u3001\u30a8\u30e9\u30fc\u51e6\u7406\u3092\u5206\u96e2\u3057\u3001\u64ec\u4f3c\u7684\u306a\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3068\u3057\u3066\u4f7f\u3063\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u4f55\u304b\u306e\u53c2\u8003\u306b\u306a\u308a\u307e\u3057\u305f\u3089\u5b09\u3057\u3044\u3067\u3059\u3002\ud83d\ude04\u2728<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6068 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_12.png\" alt=\"\" width=\"226\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_12.png 226w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_12-212x300.png 212w\" sizes=\"auto, (max-width: 226px) 100vw, 226px\" \/><\/p>\n<p style=\"text-align: center;\">\u300c\u30b5\u30f3\u30bf\u30af\u30ed\u30fc\u30b9\uff08\u81ea\u5206\uff09\u304b\u3089<br \/>\n\u826f\u3044\u5b50\uff08\u81ea\u5206\uff09\u306b Archiss \u306e\u9ad8\u7d1a\u30ad\u30fc\u30dc\u30fc\u30c9<br \/>\n\u3092\u8d08\u308a\u307e\u3057\u305f\ud83d\udc4d\u300d<\/p>\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong> Laravel 9.x\u3001React\u3001Vite\u3001Inertia.js\u3001TailwindCSS<\/p>\n<h1>\u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<p><code>Laravel<\/code>\u306b\u9650\u3089\u305a\u300c<strong>\u3042\u308b\u30c7\u30fc\u30bf\u3092\u9001\u4fe1\u3057\u3066\u767b\u9332<\/strong>\u300d\u3059\u308b\u5834\u5408\u3001\u57fa\u672c\u7684\u306b\u306f\u4ee5\u4e0b\u306e\u624b\u9806\u3067\u5b9f\u88c5\u3059\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<ol>\n<li>\u30c7\u30fc\u30bf\u9001\u4fe1<\/li>\n<li>\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3067\u4e2d\u8eab\u30c1\u30a7\u30c3\u30af<\/li>\n<li>\uff08OK \u306a\u3089\uff09DB \u767b\u9332<\/li>\n<\/ol>\n<p>\u3067\u306f\u3001\u4e0a\u306e\u4f8b\u306b<code>API<\/code>\u3078\u306e\u767b\u9332\u3082\u5fc5\u8981\u306b\u306a\u308b\u3068\u3069\u3046\u306a\u308b\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<ol>\n<li>\u30c7\u30fc\u30bf\u9001\u4fe1<\/li>\n<li>\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3067\u4e2d\u8eab\u30c1\u30a7\u30c3\u30af<\/li>\n<li>\uff08\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u304c OK \u306a\u3089\uff09API\u3078\u30c7\u30fc\u30bf\u9001\u4fe1\uff08\u767b\u9332\uff09<\/li>\n<li>\uff08API \u304c OK \u306a\u3089\uff09DB \u3078\u767b\u9332<\/li>\n<\/ol>\n<p>\u3053\u306e\u5834\u5408\u3001\u3082\u3057\uff13\u756a\u306e<code>API<\/code>\u306e\u90e8\u5206\u3067\u30a8\u30e9\u30fc\u304c\u8fd4\u3063\u3066\u304d\u305f\u3068\u3059\u308b\u3068\uff14\u756a\u76ee\u306e\u300c<strong>DB \u3078\u767b\u9332<\/strong>\u300d\u306b\u306f\u884c\u304b\u305a\u30a8\u30e9\u30fc\u51e6\u7406\u3092\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u304c\u3001\u3053\u306e\u90e8\u5206\u3092\u4eca\u56de\u306e\u72ec\u81ea\u4f8b\u5916\u3067\u5b9f\u88c5\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u5b9f\u88c5\u3059\u308b\u306e\u306f\u3001\u4eca\u56de\u306e\u30bf\u30a4\u30c8\u30eb\u306b\u3082\u3042\u308b\u3088\u3046\u306b\u300c<strong>\u64ec\u4f3c\u7684\u306a\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3<\/strong>\u300d\u3067\u3059\u3002<\/p>\n<p>\u305c\u3072\u697d\u3057\u3093\u3067\u3084\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u2757<\/p>\n<h1>\u72ec\u81ea\u306e\u4f8b\u5916\uff08Exception\uff09\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3044\u304d\u306a\u308a\u3067\u3059\u304c\u3001\u5148\u306b\u72ec\u81ea\u306e<code>Exception<\/code>\u3092\u3064\u304f\u3063\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002\uff08\u3053\u308c\u306f\u300c<code>API<\/code>\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u3068\u304d\u306b\u30a8\u30e9\u30fc\u306b\u306a\u3063\u305f\u3088\u300d\u3068\u3044\u3046\u610f\u5473\u306e\u4f8b\u5916\u3067\u3059\uff09<\/p>\n<div>\n<pre><strong>php artisan make:exception ApiAccessErrorException<\/strong><\/pre>\n<\/div>\n<p>\u306a\u304a\u3001\u4f5c\u6210\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u8eab\u306f\u5909\u66f4\u3057\u306a\u304f\u3066OK\u3067\u3059\uff01<\/p>\n<p>\u203b \u3061\u306a\u307f\u306b<code>Laravel<\/code>\u306e\u4f8b\u5916\u306b\u306f\u901a\u77e5\u6a5f\u80fd\u306a\u3069\u3082\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u305c\u3072\u305d\u306e\u4ed6\u306e\u6a5f\u80fd\u3082\u30c1\u30a7\u30c3\u30af\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002\ud83d\udc49 <a href=\"https:\/\/laravel.com\/docs\/9.x\/errors#reporting-exceptions\" target=\"_blank\" rel=\"noopener\">\u672c\u5bb6\u306e\u30da\u30fc\u30b8<\/a><\/p>\n<h1>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u3064\u304f\u308b<\/h1>\n<p>\u7d9a\u3044\u3066\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3067\u3059\u3002<br \/>\n\u3053\u3053\u3067\u5148\u307b\u3069\u306e\u72ec\u81ea\u4f8b\u5916<code>ApiAccessErrorException<\/code>\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div>\n<pre><strong>php artisan make:controller CustomExceptionController<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u3001\u4e2d\u8eab\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<\/div>\n<p><strong>app\/Http\/Controllers\/CustomExceptionController.php<\/strong><\/p>\n<div>\n<pre><strong>&lt;?php<\/strong>\r\n\r\n<strong>namespace App\\Http\\Controllers;<\/strong>\r\n\r\n<strong>use App\\Exceptions\\ApiAccessErrorException;<\/strong>\r\n<strong>use Illuminate\\Http\\Request;<\/strong>\r\n<strong>use Illuminate\\Support\\Arr;<\/strong>\r\n<strong>use Illuminate\\Support\\Facades\\Http;<\/strong>\r\n<strong>use Inertia\\Inertia;<\/strong>\r\n\r\n<strong>class CustomExceptionController extends Controller<\/strong>\r\n<strong>{<\/strong>\r\n<strong>    public function create()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        return Inertia::render('CustomException\/Create')-&gt;with([<\/strong>\r\n<strong>            'successMessage' =&gt; session('success'),<\/strong>\r\n<strong>        ]);<\/strong>\r\n<strong>    }<\/strong>\r\n\r\n<strong>    public function store(Request $request)<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        \/\/ \u901a\u5e38\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306f\u7701\u7565\u3057\u3066\u3044\u307e\u3059<\/strong>\r\n\r\n<strong>        $api_url = route('custom_exception.access_error');<\/strong>\r\n<strong>        $show_api_error = ($request-&gt;has_api_error === 'yes'); \/\/ API \u306e\u30a8\u30e9\u30fc\u3092\u51fa\u3059\u304b\u3069\u3046\u304b<\/strong>\r\n\r\n<strong>        try {<\/strong>\r\n\r\n<strong>            $response = Http::get($api_url); \/\/ API \u306b\u30a2\u30af\u30bb\u30b9<\/strong>\r\n\r\n<strong>            throw_if(<\/strong>\r\n<strong>                $show_api_error,<\/strong>\r\n<strong>                new ApiAccessErrorException($response-&gt;json('error_message'))<\/strong>\r\n<strong>            );<\/strong>\r\n\r\n<strong>            \/\/ \u5b9f\u969b\u306b\u306f\u3053\u306e\u90e8\u5206\u3067 DB \u4fdd\u5b58\u306a\u3069\u3092\u5b9f\u884c\u3057\u307e\u3059<\/strong>\r\n\r\n<strong>        } catch (ApiAccessErrorException $e) { \/\/ API \u3067\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u5834\u5408<\/strong>\r\n\r\n<strong>            $error_message = $e-&gt;getMessage();<\/strong>\r\n\r\n<strong>            \/\/ \u64ec\u4f3c\u7684\u306b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30a8\u30e9\u30fc\u3092\u8fd4\u3059<\/strong>\r\n<strong>            return back()-&gt;withErrors([<\/strong>\r\n<strong>                'api_access' =&gt; $error_message<\/strong>\r\n<strong>            ]);<\/strong>\r\n\r\n<strong>        } catch (\\Exception $e) { \/\/ \u305d\u306e\u4ed6\u306e\u30a8\u30e9\u30fc<\/strong>\r\n\r\n<strong>            throw $e;<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>        return back()-&gt;with('success', '\u4fdd\u5b58\u304c\u5b8c\u4e86\u3057\u307e\u3057\u305f\uff01');<\/strong>\r\n<strong>    }<\/strong>\r\n\r\n<strong>    public function access_error()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        $error_messages = [<\/strong>\r\n<strong>            'API \u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u306b\u4e0d\u8db3\u304c\u3042\u308a\u307e\u3059',<\/strong>\r\n<strong>            'API \u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u306b\u8aa4\u308a\u304c\u3042\u308a\u307e\u3059',<\/strong>\r\n<strong>            'API \u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u306b\u4e0d\u6b63\u306a\u5024\u304c\u3042\u308a\u307e\u3059',<\/strong>\r\n<strong>            'API \u30ad\u30fc\u304c\u7121\u52b9\u3067\u3059',<\/strong>\r\n<strong>            'API \u30b7\u30fc\u30af\u30ec\u30c3\u30c8\u30ad\u30fc\u304c\u7121\u52b9\u3067\u3059',<\/strong>\r\n<strong>        ];<\/strong>\r\n<strong>        $error_message = Arr::random($error_messages); \/\/ \u30e9\u30f3\u30c0\u30e0\u306b\u30a8\u30e9\u30fc\u3092\u8fd4\u3059<\/strong>\r\n\r\n<strong>        return response([<\/strong>\r\n<strong>            'error_message' =&gt; $error_message,<\/strong>\r\n<strong>        ], 400);<\/strong>\r\n<strong>    }<\/strong>\r\n<strong>}<\/strong><\/pre>\n<p>\u30c7\u30fc\u30bf\u9001\u4fe1\u3057\u305f\u3068\u304d\u306b\u5b9f\u884c\u3055\u308c\u308b<code>store()<\/code>\u304c\u4eca\u56de\u306e\u30e1\u30a4\u30f3\u3067\u3001\u3053\u306e\u4e2d\u3067\u300c<strong>\u4f8b\u5916\u3092\u4f7f\u3063\u305f\u5206\u5c90<\/strong>\u300d\u3092\u3057\u3066\u3044\u308b\u3053\u3068\u306b\u6ce8\u76ee\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001<code>try<\/code>\u306e\u4e2d\u3067\u306f\u3044\u304f\u3064\u304b\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3059\u304c\u3001<strong>API\u306b\u30a8\u30e9\u30fc\u304c\u3042\u3063\u305f\u3068\u304d\u3060\u3051<\/strong>\u3001<code>catch (ApiAccessErrorException $e) { ... }<\/code>\u304c\u5b9f\u884c\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u203b \u672c\u6765\u306f<code>API<\/code>\u3092\u4f7f\u3063\u305f\u51e6\u7406\u306f\u30e2\u30c7\u30eb\u3084<code>Trait<\/code>\u306a\u3069\u306b\u5206\u5272\u3059\u308b\u3068\u601d\u3046\u306e\u3067\u3001\u4f8b\u5916\u3092\u6295\u3052\u308b\u306e\u306f\u5b9f\u969b\u306b\u305d\u306e\u4e2d\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001<code>DB<\/code>\u3078\u306e\u4fdd\u5b58\u306a\u3069\u305d\u306e\u4ed6\u306e\u30a8\u30e9\u30fc\u304c\u51fa\u305f\u5834\u5408\u306f\u3001\u6b21\u306e<code>catch (\\Exception $e){ ... }<\/code>\u304c\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u203b \u4eca\u56de\u306f\u8907\u96d1\u306b\u306a\u308b\u306e\u3067\u66f8\u3044\u3066\u3044\u307e\u305b\u3093\u304c\u3001\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3067\u4e00\u6c17\u306bDB\u4fdd\u5b58\u3059\u308b\u5834\u5408\u306f\u3053\u306e\u4e2d\u3067\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\uff08\u300c\u3053\u3053\u307e\u3067\u306e<code>DB<\/code>\u4fdd\u5b58\u306f\u30ca\u30b7\u3088\u300d\u6a5f\u80fd\uff09\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001API\u30a8\u30e9\u30fc\u306e\u5834\u5408\u3001\u64ec\u4f3c\u7684\u306b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30a8\u30e9\u30fc\u3092\u5b9f\u884c\u3059\u308b\u308f\u3051\u3067\u3059\u304c\u3001\u3053\u308c\u306f\u30b7\u30f3\u30d7\u30eb\u306b<code>withErrors([ ... ])<\/code>\u306b\u30a8\u30e9\u30fc\u3092\u30bb\u30c3\u30c8\u3057\u3066\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3059\u308c\u3070<code>OK<\/code>\u3067\u3059\u3002\uff08\u3042\u3068\u3067<code>React<\/code>\u5074\u3067\u3053\u306e\u30a8\u30e9\u30fc\u3092\u53d7\u3051\u53d6\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\uff09<\/p>\n<\/div>\n<h1>\u30d3\u30e5\u30fc\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3067\u30bb\u30c3\u30c8\u3057\u305f\u30d3\u30e5\u30fc\u3092\u3064\u304f\u3063\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p><strong>resources\/js\/Pages\/CustomException\/Create.jsx<\/strong><\/p>\n<div>\n<pre><strong>import {Inertia} from \"@inertiajs\/inertia\";<\/strong>\r\n<strong>import {useState} from \"react\";<\/strong>\r\n\r\n<strong>export default function Create(props) {<\/strong>\r\n\r\n<strong>    const errors = props.errors;<\/strong>\r\n<strong>    const [hasApiError, setHasApiError] = useState('yes');<\/strong>\r\n<strong>    const successMessage = props.successMessage;<\/strong>\r\n<strong>    const handleSubmit = () =&gt; {<\/strong>\r\n\r\n<strong>        const url = route('custom_exception.store');<\/strong>\r\n<strong>        const params = {<\/strong>\r\n<strong>            has_api_error: hasApiError,<\/strong>\r\n<strong>        };<\/strong>\r\n<strong>        Inertia.post(url, params)<\/strong>\r\n\r\n<strong>    };<\/strong>\r\n\r\n<strong>    return (<\/strong>\r\n<strong>        &lt;div className=\"p-5\"&gt;<\/strong>\r\n<strong>            {successMessage &amp;&amp; (<\/strong>\r\n<strong>                &lt;div className=\"bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative mb-3\" role=\"alert\"&gt;<\/strong>\r\n<strong>                    &amp;#x1F44D; {successMessage}<\/strong>\r\n<strong>                &lt;\/div&gt;<\/strong>\r\n<strong>            )}<\/strong>\r\n<strong>            {errors.api_access &amp;&amp; (<\/strong>\r\n<strong>                &lt;div className=\"bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-3\" role=\"alert\"&gt;<\/strong>\r\n<strong>                    &amp;#x26A0; {errors.api_access}<\/strong>\r\n<strong>                &lt;\/div&gt;<\/strong>\r\n<strong>            )}<\/strong>\r\n<strong>            &lt;div className=\"mb-2 p-2\"&gt;<\/strong>\r\n<strong>                &lt;div&gt;<\/strong>\r\n<strong>                    &lt;label&gt;<\/strong>\r\n<strong>                        &lt;input<\/strong>\r\n<strong>                            type=\"radio\"<\/strong>\r\n<strong>                            value=\"has_api_error\"<\/strong>\r\n<strong>                            checked={hasApiError === 'yes'}<\/strong>\r\n<strong>                            onChange={() =&gt; setHasApiError('yes')}<\/strong>\r\n<strong>                        \/&gt; API \u3067\u30a8\u30e9\u30fc\u3092\u51fa\u3059<\/strong>\r\n<strong>                    &lt;\/label&gt;<\/strong>\r\n<strong>                &lt;\/div&gt;<\/strong>\r\n<strong>                &lt;div&gt;<\/strong>\r\n<strong>                    &lt;label&gt;<\/strong>\r\n<strong>                        &lt;input<\/strong>\r\n<strong>                            type=\"radio\"<\/strong>\r\n<strong>                            value=\"has_api_error\"<\/strong>\r\n<strong>                            checked={hasApiError === 'no'}<\/strong>\r\n<strong>                            onChange={() =&gt; setHasApiError('no')}<\/strong>\r\n<strong>                        \/&gt; \u306a\u3057<\/strong>\r\n<strong>                    &lt;\/label&gt;<\/strong>\r\n<strong>                &lt;\/div&gt;<\/strong>\r\n<strong>            &lt;\/div&gt;<\/strong>\r\n<strong>            &lt;button<\/strong>\r\n<strong>                type=\"button\"<\/strong>\r\n<strong>                className=\"text-white bg-blue-700 rounded-lg text-sm px-4 py-2\"<\/strong>\r\n<strong>                onClick={handleSubmit}&gt;\u9001\u4fe1&lt;\/button&gt;<\/strong>\r\n<strong>        &lt;\/div&gt;<\/strong>\r\n<strong>    );<\/strong>\r\n\r\n<strong>}<\/strong><\/pre>\n<p>\u3053\u306e\u4e2d\u3067\u3084\u3063\u3066\u3044\u308b\u306e\u306f\u3001\u30b7\u30f3\u30d7\u30eb\u306b\u300c<strong>\u30e9\u30b8\u30aa\u30dc\u30bf\u30f3\u3067\u30c7\u30fc\u30bf\u3092\u9078\u629e\u3057\u3066\u9001\u4fe1<\/strong>\u300d\u3060\u3051\u3067\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u305d\u306e\u30e9\u30b8\u30aa\u30dc\u30bf\u30f3\u306f\u4ee5\u4e0b\uff12\u3064\u306e\u9078\u629e\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<ul>\n<li>API \u3067\u30a8\u30e9\u30fc\u3092\u51fa\u3059<\/li>\n<li>\u306a\u3057<\/li>\n<\/ul>\n<p>\u3064\u307e\u308a\u3001\u30c6\u30b9\u30c8\u3057\u3084\u3059\u304f\u3057\u3066\u3044\u308b\u3060\u3051\u3067\u3059\u306d\ud83d\udc4d<\/p>\n<\/div>\n<h1>\u30eb\u30fc\u30c8\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u6700\u5f8c\u306b\u30eb\u30fc\u30c8\u3092\u3064\u304f\u308a\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><strong>routes\/web.php<\/strong><\/p>\n<div>\n<pre>\/\/ \u7701\u7565\r\n\r\n<strong>use App\\Http\\Controllers\\CustomExceptionController;<\/strong>\r\n\r\n<strong>Route::prefix('custom_exception')-&gt;controller(CustomExceptionController::class)-&gt;group(function(){<\/strong>\r\n\r\n<strong>    Route::get('create', 'create')-&gt;name('custom_exception.create');<\/strong>\r\n<strong>    Route::post('\/', 'store')-&gt;name('custom_exception.store');<\/strong>\r\n<strong>    Route::get('access_error', 'access_error')-&gt;name('custom_exception.access_error');<\/strong>\r\n\r\n<strong>});<\/strong><\/pre>\n<\/div>\n<p>\u3053\u308c\u3067\u4f5c\u696d\u306f\u5b8c\u4e86\u3067\u3059\u2757<\/p>\n<p>\u304a\u75b2\u308c\u69d8\u3067\u3057\u305f\ud83d\ude04\ud83d\udc4d\u2728<\/p>\n<h1>\u30c6\u30b9\u30c8\u3057\u3066\u307f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306b\u30c6\u30b9\u30c8\u3057\u3066\u307f\u307e\u3057\u3087\u3046\uff01<br \/>\n<code>Vite<\/code>\u3092\u8d77\u52d5\u3057\u3066\u3001\u300c<strong>http:\/\/******\/custom_exception\/create<\/strong>\u300d\u3078\u30a2\u30af\u30bb\u30b9\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11355\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/12\/laravel_custom_exception_1.png\" alt=\"\" width=\"202\" height=\"132\" \/><\/p>\n<p>\u3059\u308b\u3068\u3001\u4e0a\u306e\u3088\u3046\u306b\u306a\u308b\u306e\u3067\u3001\u300c<strong>API \u3067\u30a8\u30e9\u30fc\u3092\u51fa\u3059<\/strong>\u300d\u306e\u307e\u307e\u9001\u4fe1\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u3059\u308b\u3068\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11356\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/12\/laravel_custom_exception_2.png\" alt=\"\" width=\"372\" height=\"209\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/12\/laravel_custom_exception_2.png 372w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/12\/laravel_custom_exception_2-300x169.png 300w\" sizes=\"auto, (max-width: 372px) 100vw, 372px\" \/><\/p>\n<p>\u306f\u3044\u2757<\/p>\n<p>\u3046\u307e\u304f<code>API<\/code>\u7528\u306e\u30a8\u30e9\u30fc\u304c\u8fd4\u3063\u3066\u304d\u307e\u3057\u305f\u3002\uff08\u3082\u3061\u308d\u3093\u901a\u5e38\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3082\u540c\u3058\u30ed\u30b8\u30c3\u30af\u3067\u8868\u793a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\uff09<\/p>\n<p>\u3067\u306f\u3001\u6b21\u306b\u300c<strong>\u306a\u3057<\/strong>\u300d\u306b\u3057\u3066\u9001\u4fe1\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11357\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/12\/laravel_custom_exception_3.png\" alt=\"\" width=\"215\" height=\"132\" \/><\/p>\n<p>\u3046\u307e\u304f\u3044\u304f\u3067\u3057\u3087\u3046\u304b\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\uff1f\uff1f<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11358\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/12\/laravel_custom_exception_4.png\" alt=\"\" width=\"292\" height=\"213\" \/><\/p>\n<p>\u306f\u3044\u2757<br \/>\n\u4eca\u5ea6\u306f\u4fdd\u5b58\u5b8c\u4e86\u306e\u8868\u793a\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u6210\u529f\u3067\u3059\u3002\u2728\ud83d\ude04\ud83d\udc4d<\/p>\n<h1>\u4f01\u696d\u69d8\u3078\u306e\u3054\u63d0\u6848<\/h1>\n<p>\u4eca\u56de\u306e\u72ec\u81ea\u4f8b\u5916\u3092\u4f7f\u3046\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30e1\u30ea\u30c3\u30c8\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u30a8\u30e9\u30fc\u5185\u5bb9\uff08\u4eca\u56de\u306e\u4f8b\u3067\u8a00\u3046\u3068\u3001API\u306e\u30a2\u30af\u30bb\u30b9\u5931\u6557\uff09\u306a\u3069\u304c\u7279\u5b9a\u3067\u304d\u308b\u306e\u3067\u30d0\u30b0\u5bfe\u5fdc\u3057\u3084\u3059\u3044\u3002<\/li>\n<li>\u7279\u5b9a\u306e\u901a\u77e5\u3092\u5b9f\u88c5\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3001\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u8a73\u7d30\u3092\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u3067\u77e5\u3089\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u308b\uff08\u30e1\u30fc\u30eb\u3084<code>slack<\/code>\u3082OK\uff09<\/li>\n<li>\u4e00\u5ea6\u306b\u305f\u304f\u3055\u3093\u306e\u51e6\u7406\u3092\u3059\u308b\u5834\u5408\u306b\u4f8b\u5916\u306e\u5185\u5bb9\u3067\u5206\u5c90\u304c\u3067\u304d\u308b\u306e\u3067\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u3057\u3084\u3059\u3044\u3002<\/li>\n<\/ul>\n<p>\u3053\u3046\u3044\u3063\u305f\u6a5f\u80fd\u3092\u3054\u5e0c\u671b\u3067\u3057\u305f\u3089\u3044\u3064\u3067\u3082\u304a\u6c17\u8efd\u306b\u300c\u304a\u554f\u3044\u5408\u308f\u305b\u300d\u304b\u3089\u3054\u76f8\u8ac7\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u304a\u5f85\u3061\u3057\u3066\u307e\u3059\ud83d\ude04\u2728<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f\u72ec\u81ea\u306e<code>Exception<\/code>\u3092\u4f7f\u3063\u305f\u30b5\u30f3\u30d7\u30eb\u3092\u5b9f\u88c5\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u30b7\u30b9\u30c6\u30e0\u304c\u8907\u96d1\u306b\u306a\u3063\u3066\u304f\u308b\u3068\u4e00\u5ea6\u306b\u305f\u304f\u3055\u3093\u306e\u51e6\u7406\u3092\u3059\u308b\u5fc5\u8981\u304c\u51fa\u3066\u304f\u308b\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u4eca\u56de\u306e\u3088\u3046\u306a\u300c<strong>\u4f8b\u5916\u3092\u4f7f\u3063\u305f\u5206\u5c90<\/strong>\u300d\u306f\u4fbf\u5229\u306a\u306e\u3067\u3001\u305c\u3072\u6d3b\u7528\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u3001\u307e\u3060\u307e\u3060<code>Laravel<\/code>\u306b\u306f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u3082\u8f09\u3063\u3066\u3044\u306a\u3044\u3088\u3046\u306a\u60c5\u5831\u304c\u7720\u3063\u3066\u3044\u305d\u3046\u306a\u6c17\u304c\u3057\u307e\u3059\u3002\uff08\u30c8\u30ec\u30b8\u30e3\u30fc\u30cf\u30f3\u30bf\u30fc\u7684\u306a\u6c17\u5206\u3067\u3059\u306d\ud83d\ude04\uff09<\/p>\n<p>\u305c\u3072\u3053\u308c\u304b\u3089\u3082\u512a\u79c0\u306a\u65b9\u306e\u30c4\u30a4\u30c3\u30bf\u30fc\u306a\u3069\u3067\u60c5\u5831\u3092\u96c6\u3081\u3066\u3044\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\u2757<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4328 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_3.png\" alt=\"\" width=\"364\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_3.png 364w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_3-300x264.png 300w\" sizes=\"auto, (max-width: 364px) 100vw, 364px\" \/>\u300c\u6b8b\u5ff5\u306a\u304c\u3089\u5927\u962a\u6885\u7530\u306e<br \/>\n\u30b9\u30c8\u30ea\u30fc\u30c8\u30d4\u30a2\u30ce\u3001<br \/>\n\u64a4\u53bb\u3055\u308c\u3066\u307e\u3057\u305f\u2026\u6d99\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u79c1\u306fLaravel 4.2\u304b\u3089Lover\u306a\u306e\u3067\u3059\u304c\u3001\u305d\u308c\u304b\u3089\uff17\u5e74\u3050\u3089\u3044\u305f\u3063\u305f\u3044\u307e\u3067\u3082\u300c\u3048\uff01\u305d\u3093\u306a\u6a5f\u80fd\u3042\u3063\u305f\u306e\uff01\uff1f\u300d\u3068\u3044\u3046\u3082\u306e\u304c\u3042\u308a\u307e\u3059\u3002 \u7279\u306bLara &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=11352\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u3010Laravel +  React\u3011\u72ec\u81ea\u306e Exception \u3067\u64ec\u4f3c\u7684\u306a\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u3059\u308b&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":11360,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[247,3,118,249,248],"tags":[],"class_list":["post-11352","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-inertia-js","category-laravel","category-react-js","category-tailwind-css","category-vite"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/11352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11352"}],"version-history":[{"count":3,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/11352\/revisions"}],"predecessor-version":[{"id":11359,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/11352\/revisions\/11359"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/11360"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}