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 : /home/vapecompany/demo.vapecompany.com.bd/app/Http/Controllers/Backend/ |
Upload File : |
<?php namespace App\Http\Controllers\Backend; use App\Models\Area; use App\Models\Region; use App\Models\Division; use App\Models\District; use Illuminate\Http\Request; use App\Http\Controllers\Controller; class AreaController extends Controller { // public function __construct() // { // $this->middleware('auth'); // } public function index() { // if(!auth()->user()->canEvent('all_area')) // { // return redirect('/'); // } return view('area.index'); } 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 =Area::orderBy($columnName,$columnSortOrder); if($columnName_arr[0]['search']['value'] != null){ $chalans=$chalans->Where('area_id',$columnName_arr[0]['search']['value']); } if($columnName_arr[1]['search']['value'] != null){ $chalans=$chalans->Where('regions.region_name', 'like', $columnName_arr[1]['search']['value'] . '%'); } if($columnName_arr[2]['search']['value'] != null){ $chalans=$chalans->Where('divisions.division_name', 'like', $columnName_arr[2]['search']['value'] . '%'); } if($columnName_arr[3]['search']['value'] != null){ $chalans=$chalans->Where('districts.district_name', 'like', $columnName_arr[3]['search']['value'] . '%'); } if($columnName_arr[4]['search']['value'] != null){ $chalans=$chalans->Where('area_name', 'like', $columnName_arr[4]['search']['value'] . '%'); } if($columnName_arr[5]['search']['value'] != null){ $chalans=$chalans->Where('areas.status', $columnName_arr[5]['search']['value']); } $chalans=$chalans->Where('regions.status', 1); $chalans =$chalans->leftJoin('regions','areas.region_id','regions.region_id') ->leftJoin('divisions','areas.division_id','divisions.division_id') ->leftJoin('districts','areas.district_id','districts.district_id') ->select('areas.*','regions.region_name','divisions.division_name','districts.district_name'); $totalRecords =$chalans->count(); if($rowperpage < 0) { $rowperpage = 8999999999999999999; } $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_area')) { $action .='<a href="'.url('edit_area/'.$chalan->area_id).'" class="mr-2"> <i class="fa fa-edit text-warning"></i> </a> '; } $action .='</div>'; $data_arr[] = array( "area_id" => $chalan->area_id, "region_name" => $chalan->region_name, "division_name" => $chalan->division_name, "district_name" => $chalan->district_name, "area_name" => $chalan->area_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; } function get_allByReionID(Request $request){ if($request->district_id){ $areas = Area::where('district_id',$request->district_id)->get(); return $areas; } $areas = Area::where('region_id',$request->region_id)->get(); return $areas; } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { if(!auth()->user()->canEvent('new_area')) { return redirect('/'); } $regions = Region::where('status',1)->get(); $divisions = Division::where('status',1)->get(); return view('area.create',['regions'=>$regions,'divisions'=>$divisions]); } /** * 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(), [ 'area_name' => 'required|unique:areas|max:150', 'region' => 'required', 'division' => 'required', 'district' => 'required', ]); if ($validator->fails()) { return response()->json(['errors'=>$validator->errors()->all()]); }else{ //return response()->json(['re'=> auth()->user()->user_id]); $area = new Area; $area->area_name = $request->area_name; $area->region_id = $request->region; $area->division_id = $request->division; $area->district_id = $request->district; $area->status = $request->status ? $request->status : 0; $area->created_by = auth()->user()->user_id; $area->save(); } return response()->json(['errors'=>'0','success'=>$request->area_name.' is successfully added']); } /** * Display the specified resource. * * @param \App\Models\Area $area * @return \Illuminate\Http\Response */ public function show(Area $area) { // } /** * Show the form for editing the specified resource. * * @param \App\Models\Area $area * @return \Illuminate\Http\Response */ public function edit($id) { if(!auth()->user()->canEvent('edit_area')) { return redirect('/'); } $area = Area::where('area_id',$id)->first(); $regions = Region::where('status',1)->get(); $divisions = Division::where('status',1)->get(); $districts = District::where('division_id',$area->division_id)->where('status',1)->get(); return view('area.edit',['districts'=>$districts,'divisions'=>$divisions,'regions'=>$regions,'area'=>$area]); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Models\Area $area * @return \Illuminate\Http\Response */ public function update(Request $request, Area $area) { $id=$request->area_id; $validator = \Validator::make($request->all(), [ 'area_name' => 'required|max:150|unique:areas,area_name,'.$id.',area_id', 'region' => 'required', 'division' => 'required', 'district' => 'required', ]); if ($validator->fails()) { return response()->json(['errors'=>$validator->errors()->all()]); }else{ //return response()->json(['re'=> auth()->user()->user_id]); $area = Area::find($request->area_id); $area->area_name = $request->area_name; $area->region_id = $request->region; $area->division_id = $request->division; $area->district_id = $request->district; $area->status = $request->status ? $request->status : 0; $area->created_by = auth()->user()->user_id; $area->save(); } return response()->json(['errors'=>'0','success'=>$request->area_name.' is successfully Updated']); } /** * Remove the specified resource from storage. * * @param \App\Models\Area $area * @return \Illuminate\Http\Response */ public function destroy(Area $area) { // } }