Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Snapey's avatar

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();

henryoladj's avatar

@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

mware's avatar

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?

Snapey's avatar

But don't you have a different controller for category?

henryoladj's avatar

@snapey No i do not but i use it like this Route::get('category/{tag?}', 'NewsController@index')->name('news.index');

Snapey's avatar

and if you change that dd to

dd(News::latest()->get());
Snapey's avatar

i give up

your last post, the urls are identical but you say you get different results

1 like
Previous

Please or to participate in this conversation.