VaKeR CYBER ARMY
Logo of a company 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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/thread-self/root/home/vapecompany/demo.vapecompany.com.bd/app/Http/Controllers/Backend/DesignationController.php
<?php

namespace App\Http\Controllers;

use App\Models\Designation;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Auth;

class DesignationController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function __construct()
    {
        $this->middleware('auth');
       
    }
    
    public function index()
    {
       if(!auth()->user()->canEvent('all_designation'))
        {
            return redirect('/');
        }
        return view('designation.list');

    }
    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 =Designation::orderBy($columnName,$columnSortOrder);
        if($columnName_arr[0]['search']['value'] != null){
            $chalans=$chalans->Where('designation_id', $columnName_arr[0]['search']['value'] );
        }
        if($columnName_arr[1]['search']['value'] != null){
            $chalans=$chalans->Where('designation_name', 'like', $columnName_arr[1]['search']['value'] . '%');
        }
        if($columnName_arr[2]['search']['value'] != null){
            $chalans=$chalans->Where('status', $columnName_arr[2]['search']['value'] );
        }    
            
           // ->Where('designation_name', 'like', $searchValue . '%');
        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_designation'))
            {
           $action .='<a href="'.url('edit_designation/'.$chalan->designation_id).'" class="mr-2">
                                                        <i class="fa fa-edit text-warning"></i>
                                                    </a> ';
            }
            //if(auth()->user()->canEvent('viewchalan'))
           // {                                    
             // $action .='<a href="'.url('document/model/'.$chalan->category_id).'" class="mr-2">
             //                                            Documents
             //                                        </a> ';
          //  }
            $action .='</div>';
          
                                   
            $data_arr[] = array(
                "designation_id" => $chalan->designation_id,
                "designation_name" => $chalan->designation_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_designation'))
        {
            return redirect('/');
        }
       return view('designation.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(), [
            'designation_name' => 'required|unique:designations|max:150',
           
        ]);
        
        if ($validator->fails())
        {
            return response()->json(['errors'=>$validator->errors()->all()]);
        }else{
           // return  response()->json(['re'=> auth()->user()->user_id]);
            $designation =  new Designation;
            $designation->designation_name = $request->designation_name;
            $designation->status = $request->status ? $request->status : 0;
            $designation->created_by = auth()->user()->user_id;
            $designation->save();
        }
        return response()->json(['errors'=>'0','success'=>$request->designation_name.' is successfully added']);
        
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Models\Designation  $designation
     * @return \Illuminate\Http\Response
     */
    public function show(Designation $designation)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Models\Designation  $designation
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        if(!auth()->user()->canEvent('edit_designation'))
        {
            return redirect('/');
        }
        $designation=Designation::where('designation_id',$id)->first();
        return view('designation.edit',['designation'=>$designation]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\Designation  $designation
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Designation $designation)
    {
        $id=$request->designation_id;
       $validator = \Validator::make($request->all(), [
            'designation_name' => 'required|max:150|unique:designations,designation_name,'.$id.',designation_id',
           
        ]);
        
        if ($validator->fails())
        {
            return response()->json(['errors'=>$validator->errors()->all()]);
        }else{
           // return  response()->json(['re'=> auth()->user()->user_id]);
            $designation =  Designation::where('designation_id',$request->designation_id)->first();
            $designation->designation_name = $request->designation_name;
            $designation->status = $request->status ? $request->status : 0;
            $designation->updated_by = auth()->user()->user_id;
            $designation->save();
        }
        return response()->json(['errors'=>'0','success'=>$request->designation_name.' is successfully updated']);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Models\Designation  $designation
     * @return \Illuminate\Http\Response
     */
    public function destroy(Designation $designation)
    {
        //
    }
}

VaKeR 2022