【发布时间】:2016-12-28 07:17:13
【问题描述】:
我的 Productcategory.php 有
public function products()
{
return $this->hasMany('App\Models\Product');
}
Product.php 有
public function productcategory()
{
return $this->belongsTo('App\Models\Productcategory', 'category_id');
}
现在我的路线是
Route::get('gallery/{slug}', 'GalleryController@index');
当 URL 类似于 gallery/print-pattern-client-work 时,我怎样才能获得所有具有相同类别的产品?我有以下但category_id 是一个整数而不是一个蛞蝓。所以我不太确定该怎么做。
public function index()
{
$categoryslug = Request::segment(2);
$products = Productcategory::with('products')->where('category_id',$categoryslug)->get();
...
}
【问题讨论】:
-
print-pattern-client-work是任何类别吗?