Пример #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $catalog_tree = \App\Models\CatalogModel::find(1)->descendants()->get()->toTree();
     $this->line(PHP_EOL);
     $tags_ids_arr = [];
     foreach ($catalog_tree as $catalog_tree_item) {
         $children = $catalog_tree_item->children;
         if ($children->count() < 1) {
             continue;
         }
         foreach ($children as $child) {
             $tags_ids_arr[] = $child->id;
         }
     }
     $products_mix_arr = \DB::table('products')->select('id')->get();
     $products_mix_arr = array_rand($products_mix_arr, 100);
     foreach ($products_mix_arr as $product_mix) {
         \DB::table('products_tags')->insert(['tag_id' => $tags_ids_arr[rand(0, count($tags_ids_arr) - 1)], 'product_id' => $product_mix]);
         echo '.';
     }
     $this->line(PHP_EOL);
 }
Пример #2
0
<?php

$catalog_tree = \App\Models\CatalogModel::find(1)->descendants()->get()->toTree();
if (!$catalog_tree->count()) {
    return '';
}
?>

@foreach($catalog_tree as $root_item)
    <div class="col-lg-4">
        <div class="panel panel-primary">
            <div class="panel-heading">
                <h3 class="panel-title">{{ $root_item->name }}</h3>
            </div>
            <div class="panel-body">
        @foreach($root_item->children as $children_item)
            <div>
                <a href="#" data-cid="{{ $children_item->id }}">{{ $children_item->name }}</a>
                @foreach($children_item->children as $sub_children_item)
                    <a href="">{{ $sub_children_item->name }}</a>
                @endforeach
            </div>
        @endforeach
                Panel content
            </div>
        </div>
    </div>
@endforeach
 /**
  * Создание или сохранение категории
  * @param Request $request
  * @return string
  */
 public function postSaveCategory(Request $request)
 {
     $post_fields_arr = $request->all();
     /**
      * @var $category \Illuminate\Database\Eloquent\Model
      */
     if (isset($post_fields_arr['id'])) {
         $category = \App\Models\CatalogModel::find($post_fields_arr['id']);
         if (!$category) {
             return 'Ошибка: нет категории с таким ID - ' . $post_fields_arr['id'];
         }
         $category->name = $post_fields_arr['name'];
         $category->parent_id = $post_fields_arr['parent_id'];
         $category->project_id = $post_fields_arr['project_id'];
         $category->save();
     } else {
         \App\Models\CatalogModel::create($post_fields_arr);
     }
     return redirect('/seller/products');
 }
Пример #4
0
 public function render()
 {
     $catalog_tree = \App\Models\CatalogModel::find(1)->descendants()->get()->toTree();
     return view('catalog.widgets.side_nav', ['catalog_tree' => $catalog_tree]);
 }