I have following function in my controller
public function showSubCats($categoryId) {
$subcats = DB::table('sub_category as sc')
->leftJoin('products as p', 'p.sub_cat_id', '=', 'sc.sub_cat_id')
->where('sc.category_id', '=', $categoryId)
->whereNotNull('p.sub_cat_id')
->select('p.*','sc.*', DB::raw('sc.sub_cat_id AS sub_cat_id'))
->groupBy('sc.sub_cat_id')
->get();
return View::make('site.subcategory', [
'subcats' => $subcats
]);
}
This in the router
Route::get('/category/{categoryId}', ['uses' => 'CategoryProducts@showSubCats']);
And the button
<a href="{{ URL::to( '/category/' . $category->category_id) }}">View More</a>
Currently the url looks like - http://example.com/category/1 where 1 is the ID. I want to show the name instead.
I easily can make something like
Route::get('/category/{categoryId}/{name}', ['uses' => 'CategoryProducts@showSubCats']);
button
<a href="{{ URL::to( '/category/' . $category->category_id.'/'.$category->category_name) }}">View More</a>
But the ID will be still there. I can't also pass only the name of the category because if you check above query I need the ID because I'm joining tables via ID's.
Any idea how can I do this?
Laravel version 4.2