rearmustak's avatar

Making Routes based on categories

In my e-commerce I would not know how many categories shall I have, I'm not worried about subcategories right now. How can I programmatically create that category routes For example -

  • yourdomain.com/shop?category=laptops
  • yourdomain.com/shop?category=desktops

Category Table

$table->string('name');
$table->string('slug')->unique();
$table->timestamps();               	
0 likes
3 replies
bytemore's avatar

I suggest to watch this episode: https://laracasts.com/series/laravel-6-from-scratch/episodes/6

It explain how to retrieve data from the request, which is what you need.

Basically is something like this:

Example url

http://example.com/?page=2

In your controller

public function foo(Request $request) {
 dd($request->page); // the value retrieved is 2.
}

or

public function foo(Request $request) {
 dd($request->query('page');); // the value retrieved is 2.
}

Documentation: https://laravel.com/docs/7.x/requests#retrieving-input

source: https://stackoverflow.com/questions/15081090/getting-get-variable-in-laravel

1 like
rearmustak's avatar

Okay, I solved it using wildcards. I was actually following an old tutorials

  • category/{slug}

Please or to participate in this conversation.