Reputation:
I'm showing all my articles in the category index page and when clicking on edit an article is says page not found. I think the problem is that i have two ids in the url example: category/5/article/1/edit. But the url needs to be article/1/edit.
<a href="article/{{ $article->id }}/edit">Edit</a>
Route::resource('category', 'CategoryController');
Route::resource('article', 'ArticleController');
Upvotes: 0
Views: 1902
Reputation: 1814
When we make a route as resource (eg.article),it creates a named route article.edit.The url will be article/{id}/edit.
In web.php
Route::resource('article', 'ArticleController');
In view
<a href="{{ route('article.edit', ['id' => $article->id]) }}"> </a>
its similar to article/{id}/edit url
Upvotes: 0
Reputation: 2636
If you're using the resource routes/controller you could use the route()
function and pass the route name as the first parameter, and the article id as the second:
<a href="{{ route('articles.edit', $article->id) }}">Edit</a>
For more info: click here.
Upvotes: 2
Reputation: 577
Clean version:
<a href="{{ route('articles.edit', $article->id) }}">Edit</a>
Will create url with id of edited "model/resource":
articles/{id}/edit
Upvotes: 3
Reputation: 1050
Try with this
<a href="{{ url('article/'.$article->id.'/edit')}}">Edit</a>
Upvotes: 0