Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New Laravel Routes not working

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 found every time.

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

Web.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.php file structure 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?

like image 996
Jelly Bean Avatar asked Apr 16 '18 07:04

Jelly Bean


2 Answers

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

like image 190
kofoworola Avatar answered Nov 19 '22 10:11

kofoworola


I had same issue, Did all those magic with configs and nothing.. Solution: run: php artisan route:clear

like image 16
Michał Czak Avatar answered Nov 19 '22 11:11

Michał Czak