예제 #1
0
 /**
  * Cat update.
  *
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $data = $request->all();
     // dd($data);
     Cat::where('id', $id)->update($data);
     return response()->json(['message' => '更新成功'], 201);
 }
예제 #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(CatCreateRequest $request)
 {
     //  dd($request->input('sub_cats'));
     $catName = $request->input('name');
     if ($existingCat = Cat::where('name', $catName)->first()) {
         $existingCat->meta_description = $request->input('meta_description');
         $existingCat->image_class = $request->input('cat_image');
         $existingCat->save();
         if ($request->input('subcat')) {
             $newSub = new SubCat();
             $newSub->name = $request->input('subcat');
             $newSub->image_class = $request->input('sub_image');
             $newSub->cat_id = $existingCat->id;
         }
         return redirect('/admin/cat')->withSuccess("The Category '{$existingCat->name}' has been updated.");
     } else {
         $category = new Cat();
         $category->name = $request->input('name');
         $category->meta_description = $request->input('meta_description');
         $category->image_class = $request->input('cat_image');
         $category->save();
         if ($request->input('subcat')) {
             $freshSub = new SubCat();
             $freshSub->name = $request->input('subcat');
             $freshSub->image_class = $request->input('sub_image');
             $freshSub->cat_id = $category->id;
             $freshSub->save();
         }
         return redirect('/admin/cat')->withSuccess("The Category '{$category->name}' has been created.");
     }
 }
예제 #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(CatCreateRequest $request)
 {
     // dd($request->input('sub_cats'));
     $catName = $request->input('category_name');
     $subName = $request->input('subcategory_name');
     $catImage = $request->input('cat_image');
     if ($existingCat = Cat::where('name', $catName)->first()) {
         return redirect('/admin/cat/create')->withErrors("The Category '{$existingCat->name}' Is already existing");
     }
     foreach ($subName as $subb) {
         if ($existingSub = SubCat::where('name', $subb)->first()) {
             return back()->withErrors("The Sub-Category '{$existingSub->name}' Is already existing");
         }
     }
     if (!($existingImage = DB::table('subcategory')->where('name', $catImage)->first())) {
         $image = DB::table('subcategory')->insert(array('name' => $catImage));
     }
     $category = new Cat();
     $category->name = $request->input('category_name');
     $category->meta_description = $request->input('meta_description');
     $category->image_class = $catImage;
     $category->save();
     foreach ($subName as $subb) {
         $freshSub = new SubCat();
         $freshSub->name = $subb;
         $freshSub->cat_id = $category->id;
         $freshSub->save();
     }
     /*   $existingCat->meta_description=$request->input('meta_description');
                     $existingCat->image_class=$request->input('cat_image');
                     $existingCat->save();
     
                     if($request->input('subcat') ){
                     $newSub= new SubCat();
                     $newSub->name=$request->input('subcat');
                     $newSub->image_class=$request->input('sub_image');
                     $newSub->cat_id=$existingCat->id;
                      }
     
                      return redirect('/admin/cat')
                          ->withSuccess("The Category '$existingCat->name' has been updated."); */
     /*      }
                  else{
                      $category=new Cat();
                      $category->name= $request->input('category_name');
                      $category->meta_description=$request->input('meta_description');
                      $category->image_class= $request->input('cat_image');
                      $category->save();
     
                       
                         foreach($subName as $subb){
                       $freshSub=new SubCat();
                       $freshSub->name=$request->input('subcat');
                       $freshSub->image_class= $request->input('sub_image');
                       $freshSub->cat_id= $category->id;
                       $freshSub->save();
                      }  */
     return redirect('/admin/cat/')->withSuccess("The Category '{$category->name}' has been created.");
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     \Excel::load('MiRO_All Products_Pricelist.xls', function ($reader) {
         // Get workbook title
         $results = $reader->get();
         $workbookTitle = $results->getTitle();
         echo "workbookTitle: " . $workbookTitle . "<br>";
         //            $n = 0;
         foreach ($results as $sheet) {
             // get sheet title
             $sheetTitle = $sheet->getTitle();
             echo "sheetTitle: " . $sheetTitle . "<br>";
             // Check if Category exists, and if so, get category ID
             $category = Cat::where('name', $sheetTitle)->first();
             if ($category) {
                 //echo "Category exists id'" . $category->id . "'<br>";
             } else {
                 echo "Category does not exist, now adding<br>";
                 $category = new Cat();
                 $category->name = $sheetTitle;
                 $category->save();
             }
             foreach ($sheet as $cells) {
                 // Check if it's an empty line, and if so, assume this is a subcategory
                 // Check if valid data before loading into products array
                 if ($cells->sku && $cells->name && $cells->qty_1) {
                     // Check if product exists, if not, add it
                     //echo "Sheet sku: " . $cells->sku . "<br>";
                     $product = Product::where('sku', $cells->sku)->first();
                     if ($product) {
                         // Update product
                         //echo "Found a product with this SKU, updating<br>";
                         $product->name = $cells->name;
                         $product->price1 = $cells->qty_1;
                         $product->cat_id = $category->id;
                         $product->save();
                     } else {
                         // Create product
                         echo "Can't find a product with this SKU, creating<br>";
                         $product = new Product();
                         $product->sku = $cells->sku;
                         $product->name = $cells->name;
                         $product->price1 = $cells->qty_1;
                         $product->cat_id = $category->id;
                         $product->save();
                     }
                 }
                 //                    $n = $n + 1;
                 //                    if ($n > 10) {
                 //                        //break;
                 //                        dd($cells);
                 //                    }
             }
         }
     });
 }
예제 #5
0
파일: Cat.php 프로젝트: Vatia13/megaportal
 public function setSlugAttribute($slug_name)
 {
     if (empty($slug_name)) {
         $this->info = Str::generate_ge($this->attributes['name']);
         $slug_name = Cat::where('slug', '=', $this->info)->pluck('slug');
         $this->attributes['slug'] = empty($slug_name) ? $this->info : $this->info . '-' . str_random(5);
     } else {
         if (isset($_REQUEST['_method']) == 'PATCH') {
             $this->info = Str::generate_ge($slug_name);
             $slug_name = Cat::where('slug', '=', $this->info)->count();
             $this->attributes['slug'] = $slug_name <= 1 ? $this->info : $this->info . '-' . str_random(5);
         } else {
             $this->info = Str::generate_ge($slug_name);
             $slug_name = Cat::where('slug', '=', $this->data)->pluck('slug');
             $this->attributes['slug'] = empty($slug_name) ? $this->info : $this->info . '-' . str_random(5);
         }
     }
 }
예제 #6
0
 public function createTask()
 {
     $cats = Cat::where('catStatus', 1)->get();
     return view('admin.task.createTask')->with('cats', $cats);
 }
예제 #7
0
 public function edit(Cat $cat)
 {
     $categories = Cat::where('parent', 0)->get();
     return view('cats.edit', compact('cat', 'categories'));
 }
예제 #8
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     Cache::forget('cats');
     Cat::findOrFail($id)->delete();
     Cat::where('parent', $id)->delete();
     return trans('sections.section') . ' #' . $id . ' ' . trans('sections.successfully_removed');
 }
 public function show($cat, $group, $range)
 {
     $catId = Cat::where('slug', '=', $cat)->first();
     $groupId = Group::where('slug', '=', $group)->first();
     $rangeId = Range::where('slug', '=', $range)->first();
     $cat_id = "%";
     $catSlug = '0';
     $catName = '';
     if ($cat !== '0') {
         $cat_id = $catId->id;
         $catSlug = $catId->slug;
         $catName = $catId->name;
     }
     $group_id = "%";
     $groupSlug = '0';
     $groupName = '';
     if ($group !== '0') {
         $group_id = $groupId->id;
         $groupSlug = $groupId->slug;
         $groupName = $groupId->name;
     }
     $range_id = "%";
     $rangeSlug = '0';
     $rangeName = '';
     if ($range !== '0') {
         $range_id = $rangeId->id;
         $rangeSlug = $rangeId->slug;
         $rangeName = $rangeId->name;
     }
     //  return $range_id;
     //
     $results = Product::with('range', 'group')->where('cat_id', 'LIKE', $cat_id, 'AND')->where('group_id', 'LIKE', $group_id, 'AND')->where('range_id', 'LIKE', $range_id)->orderby('order')->paginate(12);
     // return $cat_id . '-' . $group_id . '-' .$range_id ;
     $groups = Group::where('cat_id', 'LIKE', $cat_id)->get();
     $ranges = Range::where('cat_id', 'LIKE', $cat_id)->orderby('order')->get();
     $keywords = $catName . ', ' . $groupName . ', ' . $rangeName;
     Session::flash('keywords', $keywords);
     Session::flash('title', $catName);
     //return $results;
     return View::make('results', compact('results', 'groups', 'groupSlug', 'ranges', 'rangeSlug', 'cat_id', 'cat', 'catSlug', 'catName', 'groupName', 'rangeName'));
     //return View::make('results');
 }