Question

I have just created UserController and added a route in the routes.php file:

Route::resource('users', 'UserController');

When I visit laravel.dev/users I expected to see the user index view, but instead I get a 404 error: The requested URL /users was not found on this server.

Here is the output when running: php artisan routes

+--------+------------------------+---------------+------------------------+----------------+---------------+
| Domain | URI                    | Name          | Action                 | Before Filters | After Filters |
+--------+------------------------+---------------+------------------------+----------------+---------------+
|        | GET users              | users.index   | UserController@index   |                |               |
|        | GET users/create       | users.create  | UserController@create  |                |               |
|        | POST users             | users.store   | UserController@store   |                |               |
|        | GET users/{users}      | users.show    | UserController@show    |                |               |
|        | GET users/{users}/edit | users.edit    | UserController@edit    |                |               |
|        | PUT users/{users}      | users.update  | UserController@update  |                |               |
|        | PATCH users/{users}    |               | UserController@update  |                |               |
|        | DELETE users/{users}   | users.destroy | UserController@destroy |                |               |
|        | GET /                  |               | Closure                |                |               |
+--------+------------------------+---------------+------------------------+----------------+---------------+

What have I done wrong?

No correct solution

OTHER TIPS

You still need a matching method in the User controller for that route (matches the "action"), if you don't have one:

public function index() {
  return "Hello world!";
}

I think there must be some other routes.php file from where your application is running. Can you check it in your application?

Assuming that your UserController is error free,

1) Make sure that the url property is configured correctly in app/config/app.php

2) Check whether your .htaccess file is working correctly.

3) Make a composer dump-autoload --optimize

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top