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

eufernando's avatar

URL dynamically

Hi! Sorry for my english.

I need create a filter like this: http://www.agroshop.com.br/ferramentas-loja

When you click the category on the left, it is added to the url.

How can I do this?

Tks

0 likes
4 replies
Reached's avatar

It's quite easy to do, I assume you are using Laravel?

VictorAvelar's avatar

If you're using Laravel, you just need to declare in your routes file something like this:

Route::get('/category/{category}', 'CategoryController@show')->name('show.categories');

Then the link in your .blade.php file, considering you know how to loop over categories collection, must look in some way like this one:

<a href="{{ route('show.categories', $category->id) }}"> X Category </a>

If you need also help with the controller I think it will be ideally the CategoryController using the show method:

Asuming you're not using v5.4

public function show($id) {
    $cat = Category::find($id);
    return view('category.show', compact('cat'));
}

If you're using 5.4

public function show($catergory) {
    return view('category.show')->with(['category' => $category];
}

To achieve the exact same behaviour that they have, you must use something like eloquent-sluggable, it's pretty easy to implement.

eufernando's avatar

@Reached Yes! I'm using Laravel 5.4.

@VictorAvelar Tks. This I know how to do. What I need is to add parameters in the url dynamically.

Open the url above and then click in some category in the left side, please.

Ex: example.com/category1/category2/category3/category4...

Like recursive.

I need declare N categories in my route?

I can not leave it in the form of infinite subcategories?

Because I cannot predict the number of subcategories that will arise.

Tks

Please or to participate in this conversation.