You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel 5.5 出现404页面未找到错误,新手求助排查

排查Laravel 5.5中「页面不存在」404错误的常见方案

Hey there, let's work through this 404 issue step by step! Based on the code snippets you shared, here are the most likely fixes to check:

  • 检查路由冲突与访问URL
    You've defined both a standalone GET /curriculum-sections route and a Route::resource for the same path. The resource route automatically generates an index method route (which duplicates your standalone GET route), but more crucially, the show method from the resource route maps to the URL GET /curriculum-sections/{curriculum_section} (note the snake_case parameter). If you're trying to access the show page, make sure you're visiting a URL like your-domain/curriculum-sections/1 (replace 1 with a valid ID from your curriculumsections table).

  • 隐式模型绑定匹配问题
    In your controller's show method, you're using implicit model binding with Curriculumsection $curriculumsection. Laravel 5.5's implicit binding relies on the route parameter name matching the variable name (or the model's route key). Since your resource route generates the parameter as curriculum_section (snake_case), but your variable is $curriculumsection (camelCase), this mismatch can cause Laravel to fail locating the model, resulting in a 404. You can fix this in two ways:

    1. Update your controller method parameter to match the route parameter:
      public function show(Curriculumsection $curriculum_section) {
          // Your logic here
      }
      
    2. Or, define a custom route key name in your Curriculumsection model:
      public function getRouteKeyName() {
          return 'id'; // Or whatever your primary key column name is
      }
      
  • 清理路由缓存
    If you've run php artisan route:cache at any point, Laravel will use cached routes instead of your updated routes/web.php file. Run this command to clear the cache and load your latest route configuration:

    php artisan route:clear
    
  • 验证控制器命名空间
    Ensure your CurriculumsectionsController is in the default App\Http\Controllers namespace. If it's placed in a subdirectory (like App\Http\Controllers\Admin), you need to specify the full namespace in your route:

    Route::resource('/curriculum-sections', 'Admin\CurriculumsectionsController');
    
  • 检查模型与数据库一致性
    Double-check that the ID you're using in the URL actually exists in your curriculumsections database table. If the record doesn't exist, Laravel's implicit binding will automatically return a 404, even if your route configuration is correct.

内容的提问来源于stack exchange,提问作者kya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:35:33