Root Zanli
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
o5t6x7pgljbm
/
public_html
/
app
/
Http
/
Controllers
/
Admin
/
Filename :
ProductCategoryController.php
back
Copy
<?php namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use App\Models\User; use App\Models\Group; use App\Models\ProductCategory; use Auth; use Hash; use Session; use DB; use Socialite; use Image; Use Response; use Helpers; //use Illuminate\Foundation\Auth\AuthenticatesUsers; //use Mail; class ProductCategoryController extends Controller { public function index() { $product_categories = ProductCategory::all(); return view('Admin.ProductCategory.index',compact('product_categories')); } public function product_category_list(Request $request) { $columns = array("product_category_name","product_category_image","product_category_id"); $columns2 =array("product_categories.product_category_name","product_categories.product_category_image","product_categories.product_category_id"); $totalData = ProductCategory::count(); $limit = $request->input('length'); $start = $request->input('start'); $dir = $request->input('order.0.dir'); $query = ProductCategory::select($columns2); $product_categories = $query->get(); $totalFiltered = $product_categories->count(); $product_categories = $query->offset($start); $product_categories = $query->limit($limit); if(isset($columns2[$request->input('order.0.column')])){ $order = $columns[$request->input('order.0.column')]; $product_categories = $query->orderBy($order,$dir); } if(isset($request->sort_by) && $request->sort_by == 1) $product_categories = $query->orderBy('product_categories.created_at', 'asc'); else $product_categories = $query->orderBy('product_categories.created_at', 'desc'); $product_categories = $query->get(); //$totalFiltered = $query->count(); $data = array(); if(!empty($product_categories)) { foreach ($product_categories as $key => $product_category) { $edit = route('product-categories.edit',$product_category->product_category_id); $delete = route('product-categories.destroy', $product_category->product_category_id); foreach ($columns as $key => $column) { if ($column == 'product_category_id') { $nestedData[$column] = "<form action='{$delete}' method='POST' id='productCategoryTable-".$product_category->$column."'> <input name='_method' type='hidden' value='DELETE'> <a href='{$edit}' title='EDIT' class='mb-6 btn-floating waves-effect waves-light gradient-45deg-green-teal gradient-shadow'> ".csrf_field()." <i class='material-icons'>edit</i></a> <button type='button' title='DELETE' class='mb-6 btn-floating waves-effect waves-light gradient-45deg-purple-deep-orange gradient-shadow' onclick='delete_product_category(".$product_category->$column.");'> <i class='material-icons'>clear</i> </button> </form>"; } else if($column == 'created_at') { $nestedData[$column] = date('j M Y h:i a',strtotime($product_category->$column)); }else if($column == 'product_category_image') { $nestedData[$column] = '<img src="'.asset($product_category->product_category_image).'" width="45px"/>'; } else { $nestedData[$column] = $product_category->$column; } } $data[] = $nestedData; } } //echo count($data);exit; $json_data = array( "draw" => intval($request->input('draw')), "recordsTotal" => intval($totalData), "recordsFiltered" => intval($totalFiltered), "data" => $data ); // echo '<pre>';print_r($json_data);die; echo json_encode($json_data); } public function create() { $product_categories = ProductCategory::get(); return view('Admin.ProductCategory.create',compact('product_categories')); } public function store(Request $request) { $validate = $request->validate([ 'product_category_name' => 'required', 'product_category_img' => 'required', ]); if($request->hasFile('product_category_img')) { $file = $request->file('product_category_img'); $imageName = rand().time().'.'.$file->getClientOriginalExtension(); // Save thumbnail image $img = Image::make($file->getRealPath()); $img->resize(100, 100, function ($constraint) { $constraint->aspectRatio(); })->save(public_path('product_images/thumb/').$imageName); // Save original size image $file->move(public_path('product_images'), $imageName); $request['product_category_image'] = $imageName; } ProductCategory::create($request->all()); return redirect()->route('product-categories.index')->with('success','Record Successfully Inserted.'); } public function edit($id) { $product_categories = ProductCategory::select('*','product_category_image as product_image')->where('product_categories.product_category_id',$id)->first(); return view('Admin.ProductCategory.edit',compact('product_categories')); } public function update(Request $request,$id) { $validate = $request->validate([ 'product_category_name' => 'required', ]); $product_categories = ProductCategory::find($id); if($request->hasFile('product_category_img')) { $file = $request->file('product_category_img'); $imageName = rand().time().'.'.$file->getClientOriginalExtension(); // Save thumbnail image $img = Image::make($file->getRealPath()); $img->resize(100, 100, function ($constraint) { $constraint->aspectRatio(); })->save(public_path('product_images/thumb/').$imageName); // Save original size image $file->move(public_path('product_images'), $imageName); $request['product_category_image'] = $imageName; } $product_categories->update($request->all()); return redirect()->route('product-categories.index')->with('success','Record Updated Successfully.'); } public function destroy($id) { $data = ProductCategory::find($id)->delete(); return redirect()->route('product-categories.index')->with('success','Record Deleted Successfully'); } }