Nicola Nicola - 5 months ago 11x
PHP Question

How can I access controller methods via url in Laravel?

I'n new to Laravel and I'm not quite sure of all the routing stuff yet, so I want to do things the way I'm comfortable with for the time, which is accessing a controller method via url. So I have a controller called User, in that a function called getLogin(). I want to access this via ''. It doesn't currently work, so how do I do this?


Laravel does not automatically map routes in controller/method fashion.

You have not posted what is in your routes.php file, but one of the simplest approaches is to do this:

Route::get('users/login', array('as' => 'login', 'uses' => 'User@getLogin'));

There are multiple approaches, though. You might consider reading the docs about routing