为什么Laravel中的新路线不起作用?

时间:2019-07-25 20:13:49

标签: php laravel

我现在已经在我的这个项目上工作了一段时间,直到今天我的路线都没有问题。

我什至尝试清除缓存和转储自动加载。似乎什么都没用。

我今天尝试添加一条新路线,但出现404错误。我也使用了“ get”和“ any”,但无济于事。

起初,我尝试创建多个新路线,但仍然遇到相同的404错误。以下是我的web.php的一部分的样子。

Route::group(['middleware' => ['auth', 'role:teacher']], function () {
    Route::any('/testing', 'PagesController@testing');


    Route::resource('/attendance', 'AttendanceController');
    Route::get('/teacher/dashboard', 'TeachersController@dashboard')->name('teacher.dashboard');
    Route::resource('homework', 'HomeworkController');
    Route::resource('/teacher/events', 'EventsController',['names' => 
    'teacher.events']);
    Route::any('/view_students', 'StudentsController@myStudents')->name('view.students');
    Route::resource('results', 'CoursesResultController');
    Route::get('/results/class_course/{id}', 'CoursesResultController@showCourseResult');
    Route::post('/results/class_course/{id}', 'CoursesResultController@saveCourseResult');


});

编辑:我已经解决了这个问题。我必须手动删除bootstrap文件夹中的缓存文件。谢谢,伙计们。

1 个答案:

答案 0 :(得分:0)

用以下代码替换代码:

Route::resource()为您生成所有可能的路线,因此应保留为最后一个可能的点。

Route::group(['middleware' => ['auth', 'role:teacher']], function () {
    Route::any('/testing', 'PagesController@testing');


    Route::resource('/attendance', 'AttendanceController');
    Route::get('/teacher/dashboard', 'TeachersController@dashboard')->name('teacher.dashboard');
    Route::resource('homework', 'HomeworkController');
    Route::resource('/teacher/events', 'EventsController',['names' => 
    'teacher.events']);
    Route::any('/view_students', 'StudentsController@myStudents')->name('view.students');

    /* changes over here
       `Route::resource()` generates all the possible routes for you, hence should be kept as the last possible point.
    */
    Route::get('/results/class_course/{id}', 'CoursesResultController@showCourseResult');
    Route::post('/results/class_course/{id}', 'CoursesResultController@saveCourseResult');
    Route::resource('results', 'CoursesResultController');

});