PATH:
home
/
lab2454c
/
sportsnovate.com
/
backups
/
core
/
app
/
Http
/
Controllers
/
Admin
<?php namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Models\Category; use App\Models\Subcategory; use App\Models\Product; use App\Models\ProductReport; use Carbon\Carbon; use Illuminate\Http\Request; use App\Models\Brand; use App\Models\ProductImage; class ProductController extends Controller { public function index() { $pageTitle = "Manage Product"; $emptyMessage = "No data found"; $categorys = Category::where('status', 1)->select('id', 'name')->get(); $products = Product::orderBy('id', 'DESC')->with('user', 'category', 'subCategory', 'brand')->paginate(getPaginate()); return view('admin.product.index', compact('pageTitle', 'emptyMessage', 'products', 'categorys')); } public function detail($id) { $pageTitle = "Manage product detail"; $product = Product::where('id',$id)->with('productSpecification.specification')->firstOrFail(); return view('admin.product.detail', compact('pageTitle', 'product')); } public function pending() { $pageTitle = "All pending products"; $emptyMessage = "No data found"; $categorys = Category::where('status', 1)->select('id', 'name')->get(); $products = Product::where('status', 0)->with('user', 'category', 'subCategory', 'brand')->orderBy('id', 'DESC')->paginate(getPaginate()); return view('admin.product.index', compact('pageTitle', 'emptyMessage', 'products', 'categorys')); } public function approved() { $pageTitle = "All approved products"; $emptyMessage = "No data found"; $categorys = Category::where('status', 1)->select('id', 'name')->get(); $products = Product::where('status', 1)->with('user', 'category', 'subCategory', 'brand')/*->whereDate('time_duration','>', Carbon::now()->toDateTimeString())*/->orderBy('id', 'DESC')->paginate(getPaginate()); return view('admin.product.index', compact('pageTitle', 'emptyMessage', 'products', 'categorys')); } public function cancel() { $pageTitle = "All cancel products"; $emptyMessage = "No data found"; $categorys = Category::where('status', 1)->select('id', 'name')->get(); $products = Product::where('status', 2)->with('user', 'category', 'subCategory', 'brand')->orderBy('id', 'DESC')->paginate(getPaginate()); return view('admin.product.index', compact('pageTitle', 'emptyMessage', 'products', 'categorys')); } public function expired() { $pageTitle = "All expired products"; $emptyMessage = "No data found"; $categorys = Category::where('status', 1)->select('id', 'name')->get(); $products = Product::whereDate('time_duration','<=', Carbon::now()->toDateTimeString())->with('user', 'category', 'subCategory', 'brand')->orderBy('id', 'DESC')->paginate(getPaginate()); return view('admin.product.index', compact('pageTitle', 'emptyMessage', 'products', 'categorys')); } public function approvBy(Request $request) { $request->validate([ 'id' => 'required|exists:products,id' ]); $product = Product::findOrFail($request->id); $product->status = 1; $product->save(); $notify[] = ['success', 'Product has been approved']; return back()->withNotify($notify); } public function cancelBy(Request $request) { $request->validate([ 'id' => 'required|exists:products,id' ]); $product = Product::findOrFail($request->id); $product->status = 2; $product->save(); $notify[] = ['success', 'Product has been cancel']; return back()->withNotify($notify); } public function search(Request $request, $scope) { $search = $request->search; $products = Product::whereHas('user',function($q) use ($search){ $q->where('username', 'like', "%$search%"); })->orWhere('title', 'like', "%$search%"); $pageTitle = ''; if($scope == 'pending'){ $products = $products->where('status', 0); }elseif($scope == 'approved'){ $products = $products->where('status', 1)->whereDate('time_duration','>', Carbon::now()->toDateTimeString()); }elseif($scope == 'cancel'){ $products = $products->where('status', 2); }elseif($scope == 'expired'){ $products = $products->whereDate('time_duration','<=', Carbon::now()->toDateTimeString()); } $categorys = Category::where('status', 1)->select('id', 'name')->get(); $products = $products->with('user', 'category', 'subCategory', 'brand')->orderBy('id', 'DESC')->paginate(getPaginate()); $pageTitle = 'Product Search - ' . $search; $emptyMessage = 'No data found'; return view('admin.product.index', compact('pageTitle', 'emptyMessage', 'products', 'categorys', 'search')); } public function productCategorySearch(Request $request, $scope) { $category = Category::where('status', 1)->where('id', $request->category_id)->firstOrFail(); $categoryId = $category->id; $pageTitle = $category->name .' '.$scope.' products list'; $emptyMessage = "No data found"; $categorys = Category::where('status', 1)->select('id', 'name')->get(); $products = Product::where('category_id', $category->id); if($scope == 'pending'){ $products = $products->where('status', 0); }elseif($scope == 'approved'){ $products = $products->where('status', 1)->whereDate('time_duration','>', Carbon::now()->toDateTimeString());; }elseif($scope == 'cancel'){ $products = $products->where('status', 2); }elseif($scope == 'expired'){ $products = $products->whereDate('time_duration','<=', Carbon::now()->toDateTimeString()); } $products = $products->with('user', 'category', 'subCategory', 'brand')->orderBy('id', 'DESC')->paginate(getPaginate()); return view('admin.product.index', compact('pageTitle', 'emptyMessage', 'products', 'categorys', 'categoryId')); } public function featuredInclude(Request $request) { $request->validate([ 'id' => 'required|exists:products,id' ]); $product = Product::findOrFail($request->id); $product->featured = 1; $product->save(); $notify[] = ['success', 'Include this product featured list']; return back()->withNotify($notify); } public function featuredNotInclude(Request $request) { $request->validate([ 'id' => 'required|exists:products,id' ]); $product = Product::findOrFail($request->id); $product->featured = 0; $product->save(); $notify[] = ['success', 'Remove this product featured list']; return back()->withNotify($notify); } public function productReport() { $pageTitle = "Product Report List"; $emptyMessage = "No data found"; $reports = ProductReport::whereHas('product', function($q){ $q->where('status', 1)/*->whereDate('time_duration','>', Carbon::now()->toDateTimeString())*/; })->latest()->with('user', 'product')->paginate(getPaginate()); return view('admin.product.report', compact('pageTitle', 'emptyMessage', 'reports')); } public function productCreate() { $data['pageTitle'] = "Add New Moments"; $data['emptyMessage'] = "No data found"; $data['brands'] = Brand::where('status', 1)->get(); //dd($data['brands']); return view('admin.product.create', $data); } public function productStore(Request $request) { //dd($request); $request->validate([ 'featured'=> 'nullable|in:1', 'title'=> 'required|max:255', 'sub_title'=> 'required|max:450', 'amount'=> 'required|numeric|gt:0', 'keyword' => 'nullable|array|min:1|max:15', 'time_duration'=> 'required|before_or_equal:today', 'category_id'=> 'required|exists:categories,id', 'sub_category'=> 'required|exists:subcategories,id', //'brand'=> 'required|exists:brands,id', // 'image'=> ['required','image',new FileTypeValidate(['jpeg', 'jpg', 'png'])], 'image'=>'required|array', 'image.*'=> 'file|mimes:jpeg,png,jpg,svg,gif,mp4,mov|max:10000', 'description' => 'required', 'package' => 'nullable|in:1,0' ]); $category = Category::where('id', $request->category_id)->where('status', 1)->firstOrFail(); $subCategory = Subcategory::where('id', $request->sub_category)->firstOrFail(); //$brand = Brand::where('id', $request->brand)->where('status', 1)->firstOrFail(); $product = new Product(); $product->title = $request->title; $product->sub_title = $request->sub_title; $product->amount = $request->amount; $product->time_duration = $request->time_duration; $product->description = $request->description; $product->featured = $request->featured ? $request->featured : null; $product->package = $request->package ? $request->package : 0; $product->keyword = $request->keyword; $product->category()->associate($category); $product->subCategory()->associate($subCategory); //$product->brand()->associate($brand); $product->save(); // dd($request->file('image')); if ($request->hasFile('image')) { foreach ($request->file('image') as $image) { $path = imagePath()['product']['path']; $size = imagePath()['product']['size']; $extension = $image->getClientOriginalExtension(); //dd($extension); if ($extension == 'mp4' || $extension == 'mov') { $filename = uploadFile($image, $path, $size); } else{ $filename = uploadImage($image, $path, $size); } // try { //$filename = uploadImage($image, $path, $size); //$product->image = $filename; //dd($filename, $product); $productImage = new ProductImage(); $productImage->file = $filename; $productImage->product()->associate($product); $productImage->save(); // } catch (\Exception $exp) { // $notify[] = ['errors', 'Image could not be uploaded.']; // return back()->withNotify($notify); // } } } $notify[] = ['success', 'Product has been created']; return redirect()->route('admin.product.index')->withNotify($notify); } public function productEdit(Product $product) { $data['pageTitle'] = "Edit Moment"; $data['emptyMessage'] = "No data found"; $data['brands'] = Brand::where('status', 1)->get(); $data['product'] = $product; return view('admin.product.edit', $data); } public function productUpdate(Request $request, Product $product) { $changed = false; $values = $request->validate([ 'featured'=> 'nullable|in:1', 'title'=> 'required|max:255', 'sub_title'=> 'required|max:450', 'amount'=> 'required|numeric|gt:0', 'keyword' => 'nullable|array|min:1|max:15', 'time_duration'=> 'required|before_or_equal:today', 'description' => 'required', 'category_id'=> 'required|exists:categories,id', 'sub_category'=> 'required|exists:subcategories,id', //'brand'=> 'required|exists:brands,id', 'image'=>'nullable|array', 'image.*'=> 'file|mimes:jpeg,png,jpg,svg,gif,mp4,mov|max:10000', 'package' => 'nullable|in:1,0' ]); $category = Category::where('id', $values['category_id'])->where('status', 1)->firstOrFail(); $subCategory = Subcategory::where('id', $values['sub_category'])->firstOrFail(); //$brand = Brand::where('id', $values['brand'])->where('status', 1)->firstOrFail(); $product->fill($request->only('featured', 'title','sub_title','amount','keyword','time_duration','description','package')); if ($product->isDirty()) { $changed = true; $product->save(); } if ($category != $product->category) { $product->category()->associate($category); $product->save(); $changed = true; } if ($subCategory != $product->subCategory) { $product->subCategory()->associate($subCategory); $product->save(); $changed = true; } // if ($brand != $product->brand) { // $product->brand()->associate($brand); // $product->save(); // $changed = true; // } /* Code Start for Multiple image upload */ $imageIds = collect($request->image_id); //dd($imageIds); /* Check If User remove images */ foreach($product->productImages as $image){ if(!$imageIds->contains($image->id)){ /* Delete Existing file from Folder */ if(\File::exists(base_path('../assets/images/product/'.$image->file))){ \File::delete(base_path('../assets/images/product/'.$image->file)); } $image->delete(); } } foreach($imageIds as $i => $id) { /* Check If User add images while update */ if($id == 0) { $path = imagePath()['product']['path']; $size = imagePath()['product']['size']; $extension = $request->image[$i]->getClientOriginalExtension(); if ($extension == 'mp4' || $extension == 'mov') { $filename = uploadFile($values['image'][$i], $path, $size); } else{ $filename = uploadImage($values['image'][$i], $path, $size); } $productImage = new ProductImage(); $productImage->file = $filename; $productImage->product()->associate($product); $productImage->save(); $changed = true; } /* Check If User update existing images while update */ else { if(isset($values['image'][$i])) { $path = imagePath()['product']['path']; $size = imagePath()['product']['size']; $extension = $request->image[$i]->getClientOriginalExtension(); if ($extension == 'mp4' || $extension == 'mov') { $filename = uploadFile($values['image'][$i], $path, $size); } else{ $filename = uploadImage($values['image'][$i], $path, $size); } $productImage = $product->productImages->where('id', "=", $id)->first(); /* Delete Existing file from Folder */ if(\File::exists(base_path('../assets/images/product/'.$productImage->file))){ \File::delete(base_path('../assets/images/product/'.$productImage->file)); } $productImage->file = $filename; $productImage->product()->associate($product); $productImage->save(); $changed = true; } } } /* Code End for Multiple image upload */ if (! $changed) { $notify[] = ['warning', 'No changes done to save']; return redirect()->route('admin.product.index')->withNotify($notify); } $notify[] = ['success', 'Product has been Updated']; return redirect()->route('admin.product.index')->withNotify($notify); } }
[-] SubcategoryController.php
[edit]
[-] CategoryController.php
[edit]
[-] FrontendController.php
[edit]
[-] PageBuilderController.php
[edit]
[-] WithdrawalController.php
[edit]
[-] SupportTicketController.php
[edit]
[-] SpecificationController.php
[edit]
[-] AdvertisementController.php
[edit]
[+]
..
[-] HomeImageController.php
[edit]
[-] DepositController.php
[edit]
[-] ProductContentController.php
[edit]
[-] ExtensionController.php
[edit]
[-] MomentContentController.php
[edit]
[-] DynamicPageController.php
[edit]
[-] ManageUsersController.php
[edit]
[-] ReportController.php
[edit]
[-] GatewayController.php
[edit]
[-] EmailTemplateController.php
[edit]
[-] FaqContentController.php
[edit]
[-] OrderController.php
[edit]
[-] BrandController.php
[edit]
[-] ManualGatewayController.php
[edit]
[-] AdminController.php
[edit]
[+]
Auth
[-] LanguageController.php
[edit]
[-] WithdrawMethodController.php
[edit]
[-] FashionNftController.php
[edit]
[-] GeneralSettingController.php
[edit]
[-] ProductController.php
[edit]
[-] SmsTemplateController.php
[edit]