/** * 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."); } }
/** * 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); // } } } }); }
public function update(Request $request, Cat $cat) { $rules = ['title' => 'required|farsi|min:5|max:80', 'cat_id' => 'required|numeric|min:1|exists:cats,id']; $messeages = ['cat_id.required' => 'از لیست دسته ها یکی را انتخاب کنید.', 'cat_id.numeric' => 'از لیست دسته ها یکی را انتخاب کنید.', 'cat_id.min' => 'از لیست دسته ها یکی را انتخاب کنید.', 'cat_id.exists' => 'دسته مورد نظر موجود نمی باشد.']; $validator = Validator::make($request->all(), $rules, $messeages); if ($validator->fails()) { return back()->withInput()->withErrors($validator); } else { # Create Category $cat->title = $request->title; $cat->parent = $request->cat_id; # Redirect on Success if ($cat->save()) { return redirect()->route('admin.cat.index')->with('success', 'دسته با موفقیت ثبت شد.'); } } return back()->withInput()->with('fail', 'مشکل در اتصال به سرور. لطفا مجددا تلاش کنید.'); }
public function addCategory(Requests\CategoryRequest $request, Cat $cat) { if ($request->ajax()) { $cat->name = $request->name; $cat->save(); } }