Server : Apache System : Linux host44.registrar-servers.com 4.18.0-513.18.1.lve.2.el8.x86_64 #1 SMP Sat Mar 30 15:36:11 UTC 2024 x86_64 User : vapecompany ( 2719) PHP Version : 7.4.33 Disable Function : NONE Directory : /proc/thread-self/root/home/vapecompany/demo.vapecompany.com.bd/app/Http/Controllers/Backend/ |
Upload File : |
<?php namespace App\Http\Controllers\Backend; use App\Http\Controllers\Controller; use App\Models\Supplier; use Illuminate\Http\Request; class SupplierController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function __construct() { $this->middleware('admin'); } public function index() { // if(!auth()->user()->canEvent('all_supplier')) // { // return redirect('/'); // } return view('backend.supplier.list'); } function get_all_supplier(Request $request){ $draw = $request->get('draw'); $start = $request->get("start"); $rowperpage = $request->get("length"); // Rows display per page $columnIndex_arr = $request->get('order'); $columnName_arr = $request->get('columns'); $order_arr = $request->get('order'); $search_arr = $request->get('search'); $columnIndex = $columnIndex_arr[0]['column']; // Column index $columnName = $columnName_arr[$columnIndex]['data']; // Column name $columnSortOrder = $order_arr[0]['dir']; // asc or desc $searchValue = $search_arr['value']; // Search value $totalRecords = supplier::count(); $suppliers =supplier::orderBy($columnName,$columnSortOrder); if($columnName_arr[0]['search']['value'] != null){ $suppliers=$suppliers->Where('supplier_id', $columnName_arr[0]['search']['value']); } if($columnName_arr[1]['search']['value'] != null){ $suppliers=$suppliers->Where('supplier_name', 'like', $columnName_arr[1]['search']['value'] . '%'); } if($columnName_arr[2]['search']['value'] != null){ $suppliers=$suppliers->Where('supplier_email', 'like', $columnName_arr[2]['search']['value'] . '%'); } if($columnName_arr[3]['search']['value'] != null){ $suppliers=$suppliers->Where('supplier_phone', 'like', $columnName_arr[3]['search']['value'] . '%'); } if($columnName_arr[4]['search']['value'] != null){ $suppliers=$suppliers->Where('supplier_mobile', 'like', $columnName_arr[4]['search']['value'] . '%'); } if($columnName_arr[5]['search']['value'] != null){ $suppliers=$suppliers->Where('supplier_website', 'like', $columnName_arr[5]['search']['value'] . '%'); } if($columnName_arr[6]['search']['value'] != null){ $suppliers=$suppliers->Where('supplier_address', 'like', $columnName_arr[6]['search']['value'] . '%'); } if($columnName_arr[7]['search']['value'] != null){ $suppliers=$suppliers->Where('status',$columnName_arr[7]['search']['value']); } if($rowperpage < 0) { $rowperpage = 8999999999999999999; } $suppliers=$suppliers->skip($start) ->take($rowperpage) ->get(); $data_arr = array(); foreach($suppliers as $supplier){ $action ='<div role="group" aria-label="Basic example" class="btn-group btn-group-sm">'; // if(auth()->user()->canEvent('edit_supplier')) // { $action .='<a href="'.url('admin/edit_supplier/'.$supplier->supplier_id).'" class="mr-2"> <i class="fa fa-edit text-warning"></i> </a> '; //} // if(auth()->user()->canEvent('s_document_list')) // { $action .='<a href="'.url('admin/document/supplier').'/'.$supplier->supplier_id.'" class="mr-2"> Docuemnt</i></a>'; // } $action .='</div>'; $data_arr[] = array( "supplier_id" => $supplier->supplier_id, "supplier_name" => $supplier->supplier_name, "supplier_email" => $supplier->supplier_email, "supplier_address" => $supplier->supplier_address, "supplier_phone" => $supplier->supplier_phone, "supplier_mobile" => $supplier->supplier_mobile, "supplier_website" => $supplier->supplier_website, "status" => $supplier->status == 1 ? 'Active' : 'In Active', "Action" => $action, ); } $response = array( "draw" => intval($draw), "recordsTotal" => $totalRecords, "recordsFiltered" => $totalRecords, "data" => $data_arr ); echo json_encode($response); exit; } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // if(!auth()->user()->canEvent('new_supplier')) // { // return redirect('/'); // } return view('backend.supplier.create'); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $validator = \Validator::make($request->all(), [ 'supplier_name' => 'required|max:150', 'supplier_email' => 'required|unique:suppliers|max:150', 'supplier_phone' => 'max:20', 'supplier_address' => 'required', 'supplier_mobile' => 'max:20', ]); if ($validator->fails()) { return response()->json(['errors'=>$validator->errors()->all()]); }else{ //return response()->json(['re'=> auth()->user()->user_id]); $supplier = new Supplier; $supplier->supplier_name = $request->supplier_name; $supplier->supplier_email = $request->supplier_email ? $request->supplier_email : ''; $supplier->supplier_phone = $request->supplier_phone ? $request->supplier_phone : ''; $supplier->supplier_address = $request->supplier_address; $supplier->supplier_mobile = $request->supplier_mobile ? $request->supplier_mobile : ''; $supplier->supplier_website = $request->supplier_website ? $request->supplier_website : ''; $supplier->status = $request->status ? $request->status : 0; $supplier->created_by = auth('admin')->user()->id; $supplier->save(); } return response()->json(['errors'=>'0','success'=> $request->supplier_name.' is successfully added']); } /** * Display the specified resource. * * @param \App\Models\Supplier $supplier * @return \Illuminate\Http\Response */ public function show(Supplier $supplier) { // } /** * Show the form for editing the specified resource. * * @param \App\Models\Supplier $supplier * @return \Illuminate\Http\Response */ public function edit($id) { //dd(auth('admin')->user()->id); // if(!auth()->user()->canEvent('edit_supplier')) // { // return redirect('/'); // } $supplier=Supplier::where('supplier_id',$id)->first(); return view('backend.supplier.edit',['supplier'=>$supplier]); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Models\Supplier $supplier * @return \Illuminate\Http\Response */ public function update(Request $request, Supplier $supplier) { $id=$request->supplier_id; $validator = \Validator::make($request->all(), [ 'supplier_name' => 'required|max:150', 'supplier_email' => 'required|max:150|unique:suppliers,supplier_email,'.$id.',supplier_id', 'supplier_phone' => 'max:14', 'supplier_address' => 'required', 'supplier_mobile' => 'max:14', ]); if ($validator->fails()) { return response()->json(['errors'=>$validator->errors()->all()]); }else{ //return response()->json(['re'=> auth()->user()->user_id]); $supplier = Supplier::find($request->supplier_id); $supplier->supplier_name = $request->supplier_name; $supplier->supplier_email = $request->supplier_email ? $request->supplier_email : ''; $supplier->supplier_phone = $request->supplier_phone ? $request->supplier_phone : ''; $supplier->supplier_address = $request->supplier_address; $supplier->supplier_mobile = $request->supplier_mobile ? $request->supplier_mobile : ''; $supplier->supplier_website = $request->supplier_website ? $request->supplier_website : ''; $supplier->status = $request->status ? $request->status : 0; $supplier->updated_by = auth('admin')->user()->id; $supplier->save(); } return response()->json(['errors'=>'0','success'=> $request->supplier_name.' is successfully updated']); } /** * Remove the specified resource from storage. * * @param \App\Models\Supplier $supplier * @return \Illuminate\Http\Response */ public function destroy(Supplier $supplier) { // } }