Route error not defined in Laravel 4

2

I'm having trouble with a link I've created in a view heading to a route . Here is the error:

ErrorException

Route [/user/addUser] not defined
.(View: /var/www/projeto/app/views/principal/index.blade.php)

Routes:

Route::get('/', function() { return View::make('principal.index'); });

Route: get ('/ user / addUser', 'AdminUserController @ addUser');

Controller:

   
class AdminUserController extends BaseController {


    public function __construct(){
        parent::__construct;
    }

    public function addUser()
    {
        return View::make('user.addUser');
    }

}

View:

   
@extends('layout.main')

@section('header')

<a href="{{URL::route('/user/addUser')}}"><button class= "btn btn-primary">Novo Cadastro</button></a>

@stop

@section('content')

@stop

@section('footer')

@stop
    
asked by anonymous 27.01.2014 / 05:37

1 answer

6

Route names in Laravel 4

One of the biggest mistakes when you start using Laravel 4 is to confuse the nome of the route with url or padrão of the route, see an example:

Route::get('/user/addUser', function(){ //algum codigo });

In the above example, the route has url or padrão being /user/AddUser but has no name, to be used in Facade URL , we should use this way:

URL::to('/user/addUser');

To give a route a name, we can do it as follows:

Route::get('/user/addUser', array(
                              'as' => 'addUserAction', 
                              'uses' => 'AdminUserController@addUser'));

Or Be: we have a route with padrão /user/addUser and its name ( named routes ) is addUserAction to make a link with Facade URL , we can now do as follows:

URL::to('/user/addUser');

or

URL::route('addUserAction');
// addUserAction é o nome que escolhi ao definir a rota na chave 'as'

In the example you posted, you are using padrão or url as if it were the route name, if the route has no name, you should use the URL::to method.

    
27.01.2014 / 10:34