Managing route and path in Laravel (named routes)

Naming routes 

If the site is massive and you will need to change routes from time to time it is best to name the routes ..

.....)->name('articles.show');

 

then in blade : {{ route('articles.show', $article->id)}}. or you just write the article variable alone without the id and laravel will figure it out

 

and insid ethe controller:

for example in the update method, you do:

return redirect(route('articles.show', $article)); 

 

 

Another alternative is to visit the model and add the following method:

 

public function path()

{

return route('articles.show', $this);

}

 

and then instead of writing:

route('article.show', $article) , you do:

$article->path()

Edit this note