JahStation JahStation - 1 year ago 145
PHP Question

Right way to build a link in laravel 5.3

Im trying to build a dynamic link with a view page (blade) with Laravel 5.3.

My approach is:

<a href=" {{ URL::to('articles') }}/{{ $article->id}}/edit">Edit></a>

that will output the right url with my base url and some other slug:

Where "23" is my article's id.

This works but I wonder if there is a cleaner way to do that?

many thanks

Answer Source

You can use named routes for this

// Your route file
URL::get('articles/{articleId}/edit', 'YourController@action')->name('articles.edit');

//Your view
<a href="{{ URL::route('articles.edit', $article->id) }}">Edit</a>

Much more cleaner IMO

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