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

gerardw85's avatar

Custom URL Question

Hello, I have the following code in my blade file {{ $tag->slug === request()->get('tag') and it's returning a URL in this format...http://www.site.test/?tag=architecto. For context, there's a list of tags on a page and clicking a tag displays all posts related to that tag.

This all works correctly, but I'm looking to display a more user-friendly url. i.e.http://site.test/architecto.

Is there a way to specify in the blade file that I want to return http://www.site.test/{{tag}}?

The other solution I'm thinking of - is creating a custom route for tags and a view for the tag page. Select a tag and it routes you to the tag view. This would allow me more flexibility / customization - and may end up being the right solution.

0 likes
2 replies
ehab.aboshehab's avatar

@gerardw85 You can use something like this

Route::get('{tag}', [SomeController::class, 'someFunction'])->name('tag');

Then in blade :

@foreach($tags as $tag)
	<a href="{{route('tag', $tag)}}">{{$tag}}</a>
@endforeach
Snapey's avatar

be aware with this approach there will be some tags that may conflict with other routes

Please or to participate in this conversation.