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; use Illuminate\Http\Request; use App\Models\ProductModel; use App\Models\Brand; use DB; class ModelController extends Controller { public function __construct() { $this->middleware('auth'); } public function index() { if(!auth()->user()->canEvent('all_model')) { return redirect('/'); } $models = DB::table('product_models')->join('brands','product_models.brand_id','brands.brand_id')->select('product_models.*', 'brands.brand_name')->get(); return view('model.list',['models'=>$models]); } function get_all(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 $chalans =ProductModel::orderBy($columnName,$columnSortOrder); if($columnName_arr[0]['search']['value'] != null){ $chalans=$chalans->Where('model_id', $columnName_arr[0]['search']['value'] ); } if($columnName_arr[1]['search']['value'] != null){ $chalans=$chalans->Where('brands.brand_name', 'like', $columnName_arr[1]['search']['value'] . '%'); } if($columnName_arr[2]['search']['value'] != null){ $chalans=$chalans->Where('model_name', 'like', $columnName_arr[2]['search']['value'] . '%'); } if($columnName_arr[3]['search']['value'] != null){ $chalans=$chalans->Where('product_models.status', $columnName_arr[3]['search']['value'] ); } $chalans =$chalans->leftJoin('brands','product_models.brand_id','brands.brand_id') ->select('product_models.*','brands.brand_name'); if($rowperpage < 0) { $rowperpage = 8999999999999999999; } $totalRecords =$chalans->count(); $chalans =$chalans->skip($start) ->take($rowperpage) ->get(); $data_arr = array(); foreach($chalans as $chalan){ $action ='<div role="group" aria-label="Basic example" class="btn-group btn-group-sm">'; if(auth()->user()->canEvent('edit_model')) { $action .='<a href="'.url('edit_model/'.$chalan->model_id).'" class="mr-2"> <i class="fa fa-edit text-warning"></i> </a> '; } if(auth()->user()->canEvent('m_document_list')) { $action .='<a href="'.url('document/model/'.$chalan->model_id).'" class="mr-2"> Documents </a> '; } $action .='</div>'; $data_arr[] = array( "model_id" => $chalan->model_id, "brand_name" => $chalan->brand_name, "model_name" => $chalan->model_name, "status" => $chalan->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_model')) { return redirect('/'); } $brands = Brand::where('status',1)->get(); return view('model.create',['brands'=>$brands]); } /** * 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(), [ 'model_name' => 'required|unique:product_models|max:150', 'brand' => 'required', ]); if ($validator->fails()) { return response()->json(['errors'=>$validator->errors()->all()]); }else{ //return response()->json(['re'=> auth()->user()->user_id]); $model = new ProductModel; $model->model_name = $request->model_name; $model->brand_id = $request->brand; $model->status = $request->status ? $request->status : 0; $model->created_by = auth()->user()->user_id; $model->save(); } return response()->json(['errors'=>'0','success'=>$request->model_name.' is successfully added']); } /** * Display the specified resource. * * @param \App\Models\Brand $brand * @return \Illuminate\Http\Response */ public function show(Model $model) { // } /** * Show the form for editing the specified resource. * * @param \App\Models\Brand $brand * @return \Illuminate\Http\Response */ public function edit($id) { if(!auth()->user()->canEvent('edit_model')) { return redirect('/'); } $brands = Brand::where('status',1)->get(); $model = ProductModel::where('model_id',$id)->first(); return view('model.edit',['brands'=>$brands,'model'=>$model]); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Models\Brand $brand * @return \Illuminate\Http\Response */ public function update(Request $request) { $id=$request->model_id; $validator = \Validator::make($request->all(), [ 'model_name' => 'required|max:150|unique:product_models,model_name,'.$id.',model_id', 'brand' => 'required', ]); if ($validator->fails()) { return response()->json(['errors'=>$validator->errors()->all()]); }else{ //return response()->json(['re'=> auth()->user()->user_id]); $model = ProductModel::find($request->model_id); $model->model_name = $request->model_name; $model->brand_id = $request->brand; $model->status = $request->status ? $request->status : 0; $model->created_by = auth()->user()->user_id; $model->save(); } return response()->json(['errors'=>'0','success'=>$request->model_name.' is successfully Updated']); } /** * Remove the specified resource from storage. * * @param \App\Models\Brand $brand * @return \Illuminate\Http\Response */ public function destroy(Model $model) { // } }