About Routes and Links

Asked

Viewed 297 times

1

I crud it, but I changed the organization of the files, instead of following the pattern, I created a user folder that contains the controller, route and model. I would like the help to try to understand why I can’t find the route by link_to_route.

Routes.php

Route::resource('/', '\App\Usuario\Http\Controllers\UsuariosController');

usuarios/index.blade.php

@foreach ($usuarios as $usuario)
<tbody>
    <tr>
        <td>{{$usuario->nome}}</td>
        <td>{{$usuario->sobrenome}}</td>
        <td>{{$usuario->email}}</td>
        <td>{{$usuario->usuario}}</td>
        <td>{{$usuario->created_at}}</td>
        <td>{{$usuario->updated_at}}</td>
        <!--É necessário uma rotas nomeada-->
        <td>{{ link_to_route('edit', $title = 'Editar', $usuario->id, $attributes = []) }}</td>
    </tr>
</tbody>
@endforeach

This is the mistake:

NotFoundHttpException in RouteCollection.php line 161

4 answers

1

Try changing to:

Route::get('/' , 'UsuariosController@metodoDoControllerUtilizado');

This should work for your case

  • Thank you Vinicius Luiz for taking the time to help me.

  • According to the solution you commented below you can remake it in a simpler way...

1


First I would like to thank Evert and Vinicius Luiz.

The solution I found was the following:

As inside the view it was with another directory in which I called Usuarios > Index.blade.php

The link_to_route modified by putting the name of the view + index to:

<td>{{ link_to_route('usuarios.edit', $title = 'Editar', $usuario->id) }}</td>

The routes continued this way:

Route::resource('usuarios', '\App\Usuario\Http\Controllers\UsuariosController');
  • 1

    You can also optionally configure the controller’s base namespace via RouteServiceProvider

1

In your view will be more or less something like this:

<td>{{ route('usuarios.edit' , [$title => 'Editar' , 'ID_USUARIO' => $usuario->id]) }}</td>

And your route will be next:

Route::get('usuarios' , ['as' => 'usuarios.edit' , 'UsuariosController@METODO']);

0

Create the structure you want, update your namespace, clear the way and just let:

Route::resource('/', 'UsuariosController');

It is necessary that your controller extend to the class Controller.

Make a:

composer dump-autoload

Try again and see if it works.

I hope I’ve helped.

  • Thank you Evert for taking the time to help me.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.