You say you don't send a tag to the index route
So you are running this line
$news= News::latest()->paginate(15);
Which has got NOTHING to do with tags or pivot table.
Check which path you are taking through the index controller using dd();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
You say you don't send a tag to the index route
So you are running this line
$news= News::latest()->paginate(15);
Which has got NOTHING to do with tags or pivot table.
Check which path you are taking through the index controller using dd();
@snapey The problem will have to do with storing the news id and tag id inside the news_tag table. The recent news ID is 31 and i used tag ID 1 with it.
But on the news_tag table the recent news ID is not 31 but 12 but the tag ID is 1
Using this
public function index(Request $request, $tag=null)
{
if($tag){
$tag=Tag::where('url',$tag)->first();
$news=$tag->news()->latest()->paginate(15);
}else{
dd();
}
return view('categories.news',compact(['news','tag']));
}
The link showing is http://localhost:8000/category/
But the post appears only once in http://localhost:8000/category/new
Okay, so with that dd() in your controller, you should get an empty page when you don't provide a tag in the link. Is that what you're getting?
But don't you have a different controller for category?
@snapey No i do not but i use it like this Route::get('category/{tag?}', 'NewsController@index')->name('news.index');
@mware yes that is what i am getting with dd();
and if you change that dd to
dd(News::latest()->get());
@snapey using
dd(News::latest()->get());
The URL is http://localhost:8000/category , but the post does not get duplicated.
But i got collection and arrays of items on http://localhost:8000/category
i give up
your last post, the urls are identical but you say you get different results
Please or to participate in this conversation.