public function run()
 {
     DB::table('suppliers')->delete();
     DB::table('categories')->delete();
     $categories = [['slug' => 'otomotif', 'name' => 'Otomotif'], ['slug' => 't-shirt', 'name' => 'T-Shirt', 'childs' => [['slug' => 'woman', 'name' => 'Woman'], ['slug' => 'man', 'name' => 'Man']]], ['slug' => 'electronic', 'name' => 'Electronic', 'childs' => [['slug' => 'laptop', 'name' => 'Laptop'], ['slug' => 'handphone', 'name' => 'Handphone']]]];
     $categories = collect($categories)->map(function ($cat) {
         $category = App\Models\Category::create(['slug' => $cat['slug'], 'name' => $cat['name']]);
         if (array_key_exists('childs', $cat)) {
             foreach ($cat['childs'] as $cate) {
                 App\Models\Category::create(['slug' => $cat['slug'], 'name' => $cat['name'], 'parent_id' => $category->id]);
             }
         }
         return $category;
     });
     $users = App\Models\User::all();
     $users->each(function ($user) use($categories) {
         $suppliers = factory(App\Models\Supplier::class, 10)->create();
         $suppliers->each(function ($supplier) use($categories, $user) {
             $supplier->users()->attach($user);
             $cat_ids = $categories->pluck('id');
             $cat_pick = $cat_ids->random();
             factory(App\Models\Product::class, 15)->create(['supplier_id' => $supplier->id, 'category_id' => $cat_pick]);
         });
     });
 }
Example #2
0
 public static function getMenu()
 {
     $category = new \App\Models\Category();
     $product = new \App\Models\Product();
     $categories = $category->getCategories(0);
     $data['categories'] = array();
     foreach ($categories as $category) {
         $children_data = array();
         if ($category['category_id'] == $data['category_id']) {
             $children = $category->getCategories($category['category_id']);
             foreach ($children as $child) {
                 $filter_data = array('filter_category_id' => $child['category_id'], 'filter_sub_category' => true);
                 $children_data[] = array('category_id' => $child['category_id'], 'name' => $child['name'] . (0 ? ' (' . $product->getTotalProducts($filter_data) . ')' : ''), 'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']));
             }
         }
         $filter_data = array('filter_category_id' => $category['category_id'], 'filter_sub_category' => true);
         $data['categories'][] = array('category_id' => $category['category_id'], 'name' => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''), 'children' => $children_data, 'href' => $this->url->link('product/category', 'path=' . $category['category_id']));
     }
     return $data;
 }
Example #3
0
<?php

Route::bind('category', function ($id) {
    $category = App\Models\Category::find($id);
    if (!$category) {
        abort(404);
    }
    return $category;
});
get('/categories', ['as' => 'categories', 'uses' => 'CategoryController@index']);
//routes to create a category
get('/category/create', ['as' => 'categoryCreate', 'uses' => 'CategoryController@create']);
post('/category/create', ['as' => 'categoryStore', 'uses' => 'CategoryController@store']);
//routes to update a category
get('/category/{category}/edit', ['as' => 'categoryEdit', 'uses' => 'CategoryController@edit']);
put('/category/{category}/edit', ['as' => 'categoryUpdate', 'uses' => 'CategoryController@update']);
//routes to delete a category
delete('/category/{category}/delete', ['as' => 'categoryDelete', 'uses' => 'CategoryController@destroy']);
Example #4
0




                    {!! Form::hidden('imgs',$category->images) !!}





                    <div class="form-group">
                        {!! Form::label('parent_id', 'Select Parent Category',['class'=>'col-sm-2 control-label']) !!}
                        <div class="col-sm-10">
                            <?php 
$roots = App\Models\Category::roots()->get();
echo "<ul id='catTree' class='tree icheck'>";
foreach ($roots as $root) {
    renderNode($root, $category);
}
echo "</ul>";
function renderNode($node, $category)
{
    echo "<li class='tree-item fl_left ps_relative_li'>";
    echo '<div class="checkbox">
                        <label class="i-checks checks-sm"><input type="checkbox"  name="parent_id" value="' . $node->id . '" ' . ($category->parent_id == $node->id ? "checked" : "") . '  /><i></i>' . $node->category . '</label>
                      </div>';
    if ($node->children()->count() > 0) {
        echo "<ul class='treemap fl_left'>";
        foreach ($node->children as $child) {
            renderNode($child, $category);
Example #5
0
                <div class="col-sm-10">
                    {!! Form::text('songtitle', null, ['id' => 'songtitle', 'class' => 'form-control', 'placeholder' => 'Songtitle']) !!}
                </div>
            </div>
            <div class="form-group">
                <label for="imgsource" class="col-sm-2 control-label">Video source</label>
                <div class="col-sm-10">
                    {!! Form::text('imgsource', null, ['id' => 'imgsource', 'class' => 'form-control', 'placeholder' => 'Video Source (This is not for links!)']) !!}
                </div>
            </div>
            <div class="form-group">
                <label for="category" class="col-sm-2 control-label">Category</label>
                <div class="col-sm-10">
                    <?php 
$categories = [];
foreach (App\Models\Category::all() as $cat) {
    $categories[$cat->id] = $cat->name;
}
?>
                    {!! Form::select('category', $categories, 8, ['id' => 'category', 'class' => 'form-control']) !!}
                </div>
            </div>
            <div class="form-group">
                <label for="nsfw" class="col-sm-2 control-label">NSFW?</label>
                <div class="col-sm-10">
                    {!! Form::checkbox('nsfw', 'true', false, ['id' => 'nsfw']) !!}
                </div>
            </div>
            <div class="form-group">
                <label for="tags_upload" class="col-sm-2 control-label">Tags</label>
                <div class="col-sm-10">
Example #6
0
 private function createCategory($categoryName, $parentCategoryName = null)
 {
     $categoryId = null;
     if ($parentCategoryName == null) {
         // Top level category
         //$existing = \App\Models\Category::where('name', '=', mb_strtoupper($categoryName))->first();
         //$existing = \DB::select('SELECT id FROM food_categories WHERE LOWER(name) = ' . mb_strtolower($categoryName));
         $existing = \DB::table('food_categories')->whereRaw('LOWER(name) = "' . mb_strtolower($categoryName) . '"')->first();
         if ($existing == null) {
             $newCat = new \App\Models\Category();
             $newCat->name = ucfirst(mb_strtolower($categoryName));
             $newCat->save();
             $categoryId = $newCat->id;
         } else {
             $categoryId = $existing->id;
         }
     } else {
         // Sub level category
         //$existingParent = \App\Models\Category::where('name', '=', mb_strtoupper($parentCategoryName))->first();
         //$existingParent = \DB::select('SELECT id FROM food_categories WHERE LOWER(name) = ' . mb_strtolower($parentCategoryName));
         $existingParent = \DB::table('food_categories')->whereRaw('LOWER(name) = "' . mb_strtolower($parentCategoryName) . '"')->first();
         if ($existingParent != null) {
             //$existing = \App\Models\Category::where('name', '=', $categoryName)->where('parent_id', '=', $existingParent->id)->first();
             //$existing = \DB::select('SELECT id FROM food_categories parent_id = ' . $existingParent->id . ' WHERE LOWER(name) = ' . mb_strtolower($parentCategoryName));
             $existing = \DB::table('food_categories')->where('parent_id', '=', $existingParent->id)->whereRaw('LOWER(name) = "' . mb_strtolower($categoryName) . '"')->first();
             if ($existing == null) {
                 $newCat = new \App\Models\Category();
                 $newCat->name = ucfirst(mb_strtolower($categoryName));
                 $newCat->parent_id = $existingParent->id;
                 $newCat->save();
                 $categoryId = $newCat->id;
             } else {
                 $categoryId = $existing->id;
             }
         }
     }
     return $categoryId;
 }