新的 Laravel 路线不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49851507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:38:45  来源:igfitidea点击:

New Laravel Routes not working

phplaravelroutesxampp

提问by Jelly Bean

I have a problem, new routes in laravel are not working, url shows the correct route but almost as if it does not get to my routes web file just returns page not foundevery time.

我有一个问题,laravel 中的新路由不起作用,url 显示了正确的路由,但几乎就像它没有到达我的路由 web 文件一样,只是每次都返回未找到的页面

I have tried: using named route, moving function to different controller, clearing route cache, clearing app cache, dump-auto load, made sure that AllowOverrideis set to All,

我试过:使用命名路由,将函数移动到不同的控制器,清除路由缓存,清除应用程序缓存转储自动加载,确保AllowOverride设置为All

Web.php:

网页.php:

    <?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

/*
|--------------------------------------------------------------------------
| Courses
|--------------------------------------------------------------------------
*/
Route::get('/courses', 'CourseController@index');
Route::get('/courses/create', 'CourseController@create');
Route::get('/courses/{course}', 'CourseController@show');
Route::get('/courses/{course}/edit', 'CourseController@edit');
Route::post('/courses', 'CourseController@store');
Route::patch('/courses/{course}', 'CourseController@update');
Route::delete('/courses/{course}', 'CourseController@destroy')->name('course-delete');

Route::get('/courses/statistics', 'CourseController@statistics');

/*
|--------------------------------------------------------------------------
| First Aid
|--------------------------------------------------------------------------
*/
Route::get('/section/{section}', 'SectionController@show');


/*
|--------------------------------------------------------------------------
| First Aid
|--------------------------------------------------------------------------
*/
Route::get('/progress', 'UserProgressController@index');
Route::get('/progress/create', 'UserProgressController@create');
Route::get('/progress/{section}', 'UserProgressController@show');
Route::get('/progress/formativeresults', 'UserProgressController@formativeresults');
//Route::get('/progress/coursestatistics', 'UserProgressController@coursestatistics');
//Route::get('/progress/{progress}/edit', 'UserProgressController@edit');
Route::post('/progress', 'UserProgressController@store');
//Route::patch('/progress/{progress}', 'UserProgressController@update');
//Route::delete('/progress/{progress}', 'UserProgressController@destroy')->name('progress-delete');

Controller:

控制器:

public function statistics()
    {
        dd('Test');
       return view('coursestatistics');
    }

View file name: coursestatistics.blade.phpfile structure views/coursestatistics

查看文件名: coursestatistics.blade.php文件结构views/coursestatistics

Link to page:

页面链接:

<a class="navbar-brand" href="/courses/statistics">
   {{ __('Statistics') }}
</a>

Can anyone tell me what might be causing route not to work?

谁能告诉我什么可能导致路线不起作用?

回答by kofoworola

Try placing

尝试放置

Route::get('/courses/statistics', 'CourseController@statistics');

below this particular line of route code

在此特定路线代码行下方

Route::get('/courses/create', 'CourseController@create');

The general rule of laravel routing is to place specific routes before wildcard routes that are related. Link here

Laravel 路由的一般规则是将特定路由放在相关的通配符路由之前。链接在这里