【发布时间】:2017-08-20 02:41:36
【问题描述】:
我的控制器中有以下功能
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
]);
}
这个在路由器里
Route::get('/category/{categoryId}', ['uses' => 'CategoryProducts@showSubCats']);
还有按钮
<a href="{{ URL::to( '/category/' . $category->category_id) }}">View More</a>
目前的 url 看起来像 - http://example.com/category/1 其中 1 是 ID。我想显示名称。
我很容易就能做出类似的东西
Route::get('/category/{categoryId}/{name}', ['uses' => 'CategoryProducts@showSubCats']);
按钮
<a href="{{ URL::to( '/category/' . $category->category_id.'/'.$category->category_name) }}">View More</a>
但 ID 仍然存在。我也不能只传递类别的名称,因为如果您检查上面的查询,我需要 ID,因为我通过 ID 加入表。
知道我该怎么做吗?
Laravel 4.2 版
【问题讨论】: