How to pass parameters to the direct resource controller of View with Helper url ()

2

I have the following route in my Laravel application (v5.5):

Route::resource('tags', 'Painel\TagsController');

As official documentation , this gives me a route with action edit, verb GET and URI (/ photos / {photo} / edit). In my View I need to generate a list, example:

<a title="Editar" href="{{ url('/painel/tags/1/edit') }}">
<a title="Editar" href="{{ url('/painel/tags/2/edit') }}">
<a title="Editar" href="{{ url('/painel/tags/3/edit') }}">

Numeric values represent the records returned from the bank and printed via loopback. I can do what I want this way:

<a title="Editar" href="{{ url('/painel/tags/' . $t->id . '/edit') }}">

However, I wanted to see if any Laravel Helper lets you do it in a more elegant way, something like:

<a title="Editar" href="{{ url('/painel/tags/edit', $t->id) }}">
    
asked by anonymous 21.09.2017 / 01:32

2 answers

0

There are two other ways you can do this:

Url from a named route (the resource already does this for us too)

echo route('tags.edit', ['id' => 1]);

// http://example.com/painel/tags/1

Url from the action of that controller in>

action('Painel\TagsController@edit', ['id' => 1]);

// http://example.com/painel/tags/1

With this, Laravel will take care of resolving the route for you, if you are using some Route::group and the like.

    
21.09.2017 / 01:40
0

You can do this using route() instead of url() , however in route() you use the path name instead of the path ... Since you used the Route::resource() method these names were given automatically, to see the name of a route you want to use you can use the command php artisan route:list it will return a list with all the routes and their information.

In your case, as it is a GET for Edit, the name will probably be 'tags.edit' so you can call the route like this: route('tags.edit', $t->id)

    
21.09.2017 / 21:27