×ðÁú¿­Ê±

laravelÔõôÌøתµ½404

laravel ÊÇÒ»¿îÊܽӴýµÄ php ¿ª·¢¿ò¼Ü £¬¿ÉÒÔÇáËɹ¹½¨¸ßЧµÄ web Ó¦ÓóÌÐò¡£ ÔÚ½¨ÉèÓ¦ÓóÌÐòʱ £¬Äú¿ÉÄÜ»áÓöµ½Ðí¶à http ¹ýʧ £¬ÀýÈç 404 ¹ýʧ. ±¾ÎĽ«ÖصãÏÈÈÝÔõÑù½« laravel Ó¦ÓóÌÐòÖеÄÁ÷Á¿Öض¨Ïòµ½×Ô½ç˵ 404 ¹ýʧҳÃæ¡£

Laravel ĬÈÏÌṩÁËÒ»¸ö¼òÆ 404 ¹ýʧҳÃæ £¬¸ÃÒ³ÃæÖ»°üÀ¨Ò»Ìõ¼òÆÓµÄÐÂÎÅ£º¡°Î´ÕÒµ½¡±¡£ ËäÈ»Õâ¹ØÓÚ¼òÆÓµÄÍøÕ¾×ã¹»ÁË £¬µ«ÈôÊÇÄúµÄÓ¦ÓóÌÐòÐèÒª¾ßÓиü¶àרҵÐԺ͸öÐÔ»¯ÄÚÈÝ £¬Äú¿ÉÄÜÐèÒª×Ô½ç˵ 404 ¹ýʧҳÃæ¡£

ÓÐÁ½ÖÖÒªÁì¿ÉÒÔ×Ô½ç˵ Laravel µÄ 404 ¹ýʧҳÃ棺ʹÓà Lumen ºÍʹÓà Laravel¡£ ÔÚ±¾ÕÂÖÐ £¬ÎÒÃǽ«ÏÈÈÝÔõÑùʹÓà Laravel ×Ô½ç˵ 404 ¹ýʧҳÃæ¡£

ÔÚ Laravel ÖÐ £¬¿ÉÒÔͨ¹ý´¦Öóͷ£³ÌÐòÍê³ÉÈκΠHTTP ¹ýʧ £¬°üÀ¨ 404 ¹ýʧ¡£ Õâ¾ÍÊÇΪʲôÔÚÐÞ¸Ä 404 ¹ýʧҳÃæ֮ǰ £¬ÐèÒªÔÚ Laravel Ó¦ÓóÌÐòÖÐ×¢²á×Ô½ç˵¹ýʧ´¦Öóͷ£³ÌÐòµÄÔµ¹ÊÔ­ÓÉ¡£

µÚÒ»²½ÊÇ·­¿ª App\Exceptions\Handler.php Îļþ £¬ÕÒµ½ render ÒªÁì¡£ÕâÊÇʹÃüµÄ½¹µã´úÂë £¬ËüÈÏÕæäÖȾ¸ø¶¨µÄÒì³£¡£Ä¬ÈÏÇéÐÎÏ £¬Laravel ʹÓà 404 ÊÓͼÎļþäÖȾ 404 ¹ýʧ¡£Òò´Ë £¬ÎÒÃÇ¿ÉÒÔÁýÕÖ´ËÒªÁì £¬²¢ÔÚÆäÖбàд´úÂëÒÔ·ºÆð×Ô½ç˵ 404 Ò³Ãæ¡£

ÒÔÏÂÊÇÁýÕÖ render ÒªÁìÒÔ´¦Öóͷ£ 404 ¹ýʧ²¢½«ÆäÖض¨Ïòµ½×Ô½ç˵ҳÃæµÄʾÀý´úÂ룺

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

    if ($exception instanceof NotFoundHttpException) {
        return response()->view('errors.404', [], 404);
    }

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

µÇ¼ºó¸´ÖÆ

ÔÚ´Ë´úÂëÖÐ £¬ÎÒÃÇÊ×ÏÈÌí¼ÓÁËÒ»ÖÖÇéÐÎ £¬ÈôÊÇÇëÇóµÄ×ÊÔ´²»ÊÇÄ£×Ó £¬Ôò·µ»Ø×Ô½ç˵ JSON ÃûÌõĹýʧÐÂÎÅ¡£ È»ºó £¬ÎÒÃÇÌí¼ÓÁíÒ»¸öÌõ¼þ £¬ÈôÊDZ¬·¢ NotFoundHttpException ¹ýʧ £¬ÎÒÃǽ«Öض¨Ïòµ½×Ô½ç˵ 404 ÊÓͼÎļþ¡£

Ö÷ÒªµÄÊÇÒª¼Ç×Å £¬ÎÒÃÇÐèÒªÔÚ resources/views/errors Ŀ¼Öн¨Éè×Ô½ç˵ 404 ÊÓͼÎļþ £¬ÒÔ±ã Laravel ¿ÉÒÔ׼ȷ·ºÆð×Ô½ç˵ҳÃæ¡£ ½ñÊÀÂëÖеÄÒì³£´¦Öóͷ£³ÌÐò¼ì²âµ½ 404 ¹ýʧʱ £¬Ëü½«Öض¨Ïòµ½´ËÎļþ¾ÙÐÐäÖȾ¡£

³ýÁË×Ô½ç˵ 404 Ò³ÃæÖ®Íâ £¬Äú»¹¿ÉÒÔ×Ô½ç˵ÆäËû HTTP ¹ýʧҳÃæ £¬ÀýÈç 403¡¢500 »ò 503 Ò³Ãæ¡£ Ö»ÐèʹÓÃÏàͬµÄÒªÁì £¬µ«ÏìÓ¦µØ¸ü¸ÄÒì³£´¦Öóͷ£³ÌÐòÖеÄÌõ¼þ¼´¿É¡£

×ܽá

ÔÚ¿ª·¢ Laravel Ó¦ÓóÌÐòʱ £¬´¦Öóͷ£³£¼ûµÄ HTTP ¹ýʧ£¨ÀýÈç 404 ¹ýʧ£©ÊÇÖÁ¹ØÖ÷ÒªµÄ¡£ ÔÚ±¾ÎÄÖÐ £¬ÎÒÃÇÏàʶÁËÔõÑùʹÓà Laravel ×Ô½ç˵ 404 ¹ýʧҳÃæ £¬°üÀ¨±àд×Ô½ç˵Òì³£´¦Öóͷ£³ÌÐòºÍÊÓͼÎļþ¡£Í¨¹ý×Ô½ç˵ 404 ¹ýʧҳÃæ £¬Äú¿ÉÒÔÇáËÉÓÅ»¯Óû§ÌåÑé £¬²¢Ìá¸ßÓ¦ÓóÌÐòµÄ¿ÉÓÃÐÔ¡£

ÒÔÉϾÍÊÇlaravelÔõôÌøתµ½404µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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