×ðÁú¿­Ê±

laravel ¹ýʧ´¦Öóͷ£

laravelÊÇÒ»¸öÊ¢ÐеÄphp¿ò¼Ü £¬ËüÌṩÁËÐí¶à¹ýʧ´¦Öóͷ£»úÖÆ £¬×ÊÖú¿ª·¢Õ߸üÇáËɵص÷ÊԺʹ¦Öóͷ£³ÌÐòÖеĹýʧ¡£ÔÚ±¾ÎÄÖÐ £¬ÎÒÃǽ«Ì½ÌÖlaravelµÄ¹ýʧ´¦Öóͷ£»úÖÆ¡£

ÉèÖÃÎļþ

LaravelµÄÉèÖÃÎļþconfig/app.phpÖÐÓÐÒ»¸ökeyֵΪdebugµÄÑ¡Ïî¡£µ±debugΪtrueʱ £¬Laravel»áÏÔʾÏêϸµÄ¹ýʧÐÅÏ¢ £¬±ãÓÚ¿ª·¢Ö°Ô±µ÷ÊÔ³ÌÐò¡£µ±ÉèÖÃΪfalseʱ £¬ÔòÖ»ÏÔʾһÑùƽ³£µÄ¹ýʧÐÅÏ¢¡£

Òì³£´¦Öóͷ£

LaravelÖÐʹÓÃÒì³£´¦Öóͷ£À´²¶»ñ´úÂëÖеĹýʧ¡£µ±³ÌÐòÖб¬·¢¹ýʧʱ £¬Laravel»áÅ׳öÒ»¸öÒì³£ £¬Õâ¸öÒì³£½«±»ÏµÍ³´¦Öóͷ£¡£

ÎÒÃÇ¿ÉÒÔÔÚapp/Exceptions/Handler.phpÎļþÖбàд´úÂëÀ´´¦Öóͷ£Òì³£¡£ÔÚÕâ¸öÎļþÖÐ £¬ÓÐÒ»¸öÒªÁì½Ð×örender £¬Õâ¸öÒªÌå»á±»×Ô¶¯Å²ÓÃÒÔäÖȾÒì³£¡£ÎÒÃÇ¿ÉÒÔÔÚÕâ¸öÒªÁìÖнç˵ÈçÄÇÀïÖÃÒì³£¡£ÏÂÃæÊÇÒ»¸öÀý×Ó£º

public function render($request, Exception $exception)
{
    if ($exception instanceof IlluminateDatabaseEloquentModelNotFoundException) {
        return response()->json([
            'error' => 'Resource not found'
        ], 404);
    }

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

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÀý×ÓÖÐ £¬ÎÒÃÇÅжÏÁËÒì³£ÀàÐÍ £¬ÈôÊÇÊÇModelNotFoundException £¬¾Í·µ»ØÒ»¸ö404¹ýʧºÍÒ»¸öjsonÃûÌõÄÏìÓ¦ £¬¸æËß¿Í»§¶Ë×ÊԴδÕÒµ½¡£ÈôÊDz»ÊÇÕâ¸öÒì³£ÀàÐÍ £¬¾ÍŲÓø¸ÀàµÄrenderÒªÁì¾ÙÐд¦Öóͷ£¡£

ÈÕÖ¾¼Í¼

³ýÁËÔÚ¿ØÖÆ̨»òÕßä¯ÀÀÆ÷ÉÏÏÔʾ¹ýʧÐÅÏ¢ £¬Laravel»¹Ö§³Ö½«¹ýʧÐÅÏ¢¼Í¼µ½ÈÕÖ¾ÎļþÖС£ÕâÑù¿ÉÒÔ¸üÀû±ãµØ×·×ٺ͵÷ÊÔ³ÌÐòÖеĹýʧ¡£

LaravelĬÈÏʹÓÃMonolog¿âÀ´¼Í¼ÈÕÖ¾¡£ÎÒÃÇ¿ÉÒÔͨ¹ýÐÞ¸ÄÉèÖÃÎļþÖеÄÈÕ־ѡÏîÀ´ÉèÖÃÈÕÖ¾¼Í¼¼¶±ðºÍÈÕÖ¾ÎļþλÖá£

'log' => env('APP_LOG', 'single'),

'log_level' => env('APP_LOG_LEVEL', 'debug'),

'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['single'],
        ],

        'single' => [
            'driver' => 'single',
            'path' => storage_path('logs/laravel.log'),
            'level' => 'debug',
        ],
]

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÉèÖÃÎļþÖÐ £¬ÎÒÃÇ¿ÉÒÔ¿´µ½Laravel»á½«ÈÕÖ¾¼Í¼µ½/storage/logs/laravel.logÎļþÖÐ £¬²¢ÇҼͼËùÓÐdebug¼¶±ð¼°ÒÔÉϵÄÈÕÖ¾¡£

×Ô½ç˵¹ýʧҳÃæ

µ±³ÌÐòÖб¬·¢¹ýʧʱ £¬Ä¬ÈÏÇéÐÎÏÂLaravel»áÏÔʾһ¸ö¼òÆӵĹýʧ½çÃæ¡£¿ÉÊÇÎÒÃÇÒ²¿ÉÒÔ×Ô½ç˵¹ýʧҳÃæ £¬ÒÔµÖ´ï¸üÓÅÃÀºÍ×Ô¼ºÐèÒªµÄЧ¹û¡£

ÎÒÃÇ¿ÉÒÔ½¨Éè×Ô¼ºµÄÊÓͼÎļþ £¬²¢½«ËüÃÇ·ÅÔÚresources/views/errorsĿ¼Ï¡£È»ºóÔÚapp/Exceptions/Handler.phpÎļþÖÐÖØдrenderÒªÁì £¬µ±±¬·¢Ò쳣ʱÏÔʾÎÒÃÇ×Ô½ç˵µÄÊÓͼҳÃ档ʾÀý´úÂëÈçÏ£º

public function render($request, Exception $exception)
{
    if ($this->isHttpException($exception)) {
        if ($exception->getStatusCode() == 404) {
            return response()->view('errors.404', [], 404);
        }
    }

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

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÀý×ÓÖÐ £¬ÎÒÃǽç˵ÁËÒ»¸ö404¹ýʧҳÃæ £¬²¢ÔÚrenderÒªÁìÖÐÅжÏ״̬ÂëÊÇ·ñΪ404¡£ÈôÊÇÊÇ £¬¾Í·µ»ØÎÒÃǸոս¨ÉèµÄÊÓͼҳÃæ¡£

×ܽá

LaravelÌṩÁËÐí¶à¹ýʧ´¦Öóͷ£»úÖÆ £¬Ê¹¿ª·¢Ö°Ô±¸üÇáËɵش¦Öóͷ£¹ýʧ¡£ÎÒÃÇ¿ÉÒÔͨ¹ýÉèÖÃÎļþ¡¢Òì³£´¦Öóͷ£¡¢ÈÕÖ¾¼Í¼ºÍ×Ô½ç˵¹ýʧҳÃæµÈ·½·¨À´ÕƿسÌÐòÖÐËùÓйýʧ¡£

ËäÈ» £¬ÓÅÒìµÄ³ÌÐòÔ±Òª¾¡¿ÉÄÜïÔÌ­³ÌÐòÖеĹýʧ·ºÆ𠣬×èÖ¹ÔÚºóÆÚ²ÅÐÐÖ¹ÖÃÏ¢Õù¾ö¹ýʧ £¬ÓÉÓÚ¾¡¿ÉÄÜïÔÌ­¹ýʧµÄ·ºÆ𠣬²»µ«¿ÉÒÔÌá¸ß³ÌÐòÐÔÄÜ £¬»¹¿ÉÒÔ´ó´óïÔÌ­ºóÆÚά»¤µÄ¾«Éñ±¾Ç®¡£

ÒÔÉϾÍÊÇlaravel ¹ýʧ´¦Öóͷ£µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±ÊµÊ±ÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿