我试着:
subspecifications
subspecifications
以在其他输入中选择category_id
列subspecifications
将保存在名为的第3个表中
product_subspecification
product_id
和subspecification_id
存储public function create()
{
//get all categories, so i can select
$categories = Category::all();
// find category id of chosen ones
$categories2 = Category::all();
foreach($categories2 as $cats){
$catid = $cats->id;
}
//get subspecifications in selected categories
$subspecifications = DB::table('product_subspecification')
->join('products','products.category_id', '=', $catid)
->join('subspecifications', 'subspecifications.id', '=', 'product_subspecification.subspecification_id')
->get();
$statuses = Status::all();
return view('admin.landings.create', compact('categories', 'subspecifications', 'statuses'));
}
product_subspecification
它假设像下面的图像一样工作:
我明白了:
SQLSTATE [42S22]:未找到列:1054未知列' 3'在'上 条款' (SQL:select * from
products
inner joinproducts
。category_id
=3
内部联接subspecifications
subspecifications
上的id
。product_subspecification
=subspecification_id
。public function create() { $categories = Category::all(); $categories2 = Category::all(); foreach($categories2 as $cats){ $catid = $cats->id; } $subspecifications = DB::table('products') ->where('category_id', $catid) ->join('product_subspecification', 'product_subspecification.product_id', '=', 'products.id') ->join('subspecifications', 'subspecifications.id', '=', 'product_subspecification.subspecification_id') ->groupBy('subspecifications.id') ->get(); $statuses = Status::all(); return view('admin.landings.create', compact('categories', 'subspecifications', 'statuses')); }
)
有什么想法吗?
我做了类似的事情:
core i3
似乎有效但有两个问题:
core i3
我选择两个护理时的类别subspecifications
2次$attrib=["last","featured","disabled"];
->whereIn('attrib',[$attrib])->get();
。