未找到Laravel内部联接列

时间:2018-02-28 09:33:17

标签: php laravel

我试着:

  1. 选择类别
  2. 从这些类别中搜索产品subspecifications
  3. 返回subspecifications以在其他输入中选择
  4. 逻辑

    1. 产品有category_id
    2. 产品subspecifications将保存在名为的第3个表中 product_subspecification product_idsubspecification_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')); }
    3. 代码

      product_subspecification

      问题

      它假设像下面的图像一样工作:

      screen1

      我明白了:

        

      SQLSTATE [42S22]:未找到列:1054未知列' 3'在'上   条款' (SQL:select * from products inner join   productscategory_id = 3内部联接subspecifications   subspecifications上的idproduct_subspecification =   subspecification_idpublic 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

      似乎有效但有两个问题:

      1. 我的数据正在重复,例如,如果我在2中使用core i3 我选择两个护理时的类别subspecifications 2次
      2. 如果我从输入1中删除了他们的类别,我需要删除$attrib=["last","featured","disabled"]; ->whereIn('attrib',[$attrib])->get();

0 个答案:

没有答案