davdjurgens's avatar

Route not working

I'm just learning laravel and been following Laravel 5.4 from scratch while setting up my own project. Everything was fine until I added another route.

This is what my routes/web.php looks like now:

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


Route::get('logs', 'LogsController@index') ;

Route::get('logs/{log}', 'LogsController@show');

Route::get('logs/create', 'LogsController@create');

The first 3 routes work, I added them earlier. When I go to the last route using http://project.test/logs/create I just get a Page Not Found. No syntax error or anything... just a 404.

I ran php artisan route:list which returned this:

+--------+----------+-------------+------+--------------------------------------------+--------------+
| Domain | Method   | URI         | Name | Action                                     | Middleware   |
+--------+----------+-------------+------+--------------------------------------------+--------------+
|        | GET|HEAD | /           |      | Closure                                    | web          |
|        | GET|HEAD | api/user    |      | Closure                                    | api,auth:api |
|        | GET|HEAD | logs        |      | App\Http\Controllers\LogsController@index  | web          |
|        | GET|HEAD | logs/create |      | App\Http\Controllers\LogsController@create | web          |
|        | GET|HEAD | logs/{log}  |      | App\Http\Controllers\LogsController@show   | web          |
+--------+----------+-------------+------+--------------------------------------------+--------------+

That looks right.

I ran php artisan config:cache, php artisan route:clear and php artisan cache:clear and cleared browser cache. Still no change.

What am I missing here? It's not telling me it can't find the function in the controller, even when I give it a function that doesn't exists. Giving it the function of index doesn't work either.

0 likes
9 replies
davdjurgens's avatar

Here's the LogsController.php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\log;

class LogsController extends Controller
{
    public function index() {
        $logs = Log::all();
        return view('logs.index', compact('logs'));
    }

    public function show(Log $log) {
        return view('logs.show', compact('log'));
    }

    public function create() {
        return view('logs.create');
    }
}
Talinon's avatar
Talinon
Best Answer
Level 51

Your {logs} wildcard route is preventing your logs/create route from being reached. Simply move the last route so it's before it:

Route::get('logs/create', 'LogsController@create');

Route::get('logs/{log}', 'LogsController@show');

6 likes
ghsom's avatar

Have you guys found a soultion ?

HashmatWaziri's avatar

Hello! I also encountered this problem before. Please check your Apache's httpd.conf file. Make sure that you enabled the LoadModule rewrite_module modules/mod_rewrite.so by removing the # from the start line of the code.

And also change inside the httpd.conf from Require all denied to Require all granted, AllowOverride All, and Options Indexes FollowSymLinks

Like This: Capture

Krubbit's avatar

For those still looking, i had no wildcards and the rutes where failing to load just run php artisan optimize

Priyanka Rathod's avatar

Just You have to set on your terminal :-

php artisan route:clear
2 likes

Please or to participate in this conversation.