xmarston xmarston - 1 year ago 208
PHP Question

Laravel 5.1 Route not defined

I'm developing a webapp with Laravel 5.1 and I started doing the user authentication, I added this routes to the routes.php file:

Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::get('auth/logout', 'Auth\AuthController@getLogout');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::post('auth/register', 'Auth\AuthController@postRegister');

And it works if I enter the link into the url bar but if I put in a template this syntax:

<a href="{{ URL::route('auth/register') }}">Registra't</a>

I get the error Route [auth/register] not defined. What I'm doing wrong? Is there anything else to do?

Answer Source

URL::route() expect a named route, here you should use URL::to() or you can create a named route with

Route::get('auth/register', [
  'as' => 'register', 
  'uses' => 'Auth\AuthController@getRegister'

Then use URL::route('register') to link to the route auth/register

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download