dyjh il y a 6 ans
Parent
commit
345cb0afe3

+ 0 - 3
app/Http/Controllers/Admin/Album/CatController.php

xqd
@@ -44,11 +44,8 @@ class CatController extends Controller
         $list = $query->paginate();
         foreach ($list as $key => $item) {
             //dump($item);
-
             $item->sonlist = AlbumCatModel::where([['parent_id',$item->id],['store_id',$this->getStoreId()]])->orderByDesc('sort')->get();
-
         }
-//        dump($list);
         return view('admin.album.cat.index', compact('list'));
     }
 

+ 10 - 2
app/Http/Controllers/Admin/Album/ProductController.php

xqd
@@ -179,12 +179,20 @@ class ProductController extends Controller
         if ($request->method() == 'POST') {
             return $this->_updateSave();
         }
-        $cat = AlbumCatModel::where([['store_id',$this->getStoreId()],['parent_id','!=',0]])->get();
+        $cat = AlbumCatModel::where([['store_id',$this->getStoreId()],['parent_id', 0]])->get();
+        foreach ($cat as $key => $val) {
+            $son = AlbumCatModel::where([['store_id',$this->getStoreId()],['parent_id', $val['id']]])->get();
+            $category[] = [
+                'id' => 0,
+                'name' => $val['name'],
+                'son' => $son
+            ];
+        }
         $data = $this->repository->find($request->get('id'));
         $data['install_img'] = json_decode($data['install_img']);
         $data['specifications_img'] = json_decode($data['specifications_img']);
         $data['detail'] = json_decode($data['detail']);
-        return view('admin.album.product.edit', compact('data', 'cat', 'parent'));
+        return view('admin.album.product.edit', compact('data', 'category', 'parent'));
     }
 
     /**

+ 6 - 3
resources/views/admin/album/product/edit.blade.php

xqd
@@ -50,9 +50,12 @@
 
                                         <div class="col-sm-3">
                                             <select id="data_parent_id" class="form-control" name="data[cat_id]" >
-                                                @if(isset($cat))
-                                                    @foreach($cat as $key=>$val)
-                                                        <option value="{{$val->id}}"  @if($val['id'] == (isset($data['cat_id'])? $data['cat_id']:''))selected @endif>{{$val->name}}</option>
+                                                @if(isset($category))
+                                                    @foreach($category as $key=>$val)
+                                                        <option value="0">{{$val['name']}}</option>
+                                                        @foreach($val['son'] as $index=>$item)
+                                                            <option value="{{$item->id}}"  @if($item['id'] == (isset($data['cat_id'])? $data['cat_id']:''))selected @endif>{{$item->name}}</option>
+                                                        @endforeach
                                                     @endforeach
                                                 @endif
                                             </select>