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 :  /home/vapecompany/demo.vapecompany.com.bd/app/Http/Controllers/Backend/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/vapecompany/demo.vapecompany.com.bd/app/Http/Controllers/Backend/BankBranchController.php
<?php

namespace App\Http\Controllers\Backend;

use App\Models\BankBranch;
use App\Models\Bank;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class BankBranchController 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_branch'))
        // {
        //     return redirect('/');
        // }
        $branchs = BankBranch::get();
        return view('backend.bank_branch.index',['branchs'=>$branchs]);
    }
     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

        $totalRecords = BankBranch::count();
        $couriers =BankBranch::orderBy($columnName,$columnSortOrder)
            ->leftJoin('banks','bank_branches.bank_id','banks.bank_id')
            ->select('bank_branches.*','banks.bank_name');
            if($columnName_arr[0]['search']['value'] != null){
                $couriers=$couriers->Where('bank_branch_id', 'like', $columnName_arr[0]['search']['value'] . '%');
            }
            if($columnName_arr[1]['search']['value'] != null){
                $couriers=$couriers->Where('bank_name', 'like', $columnName_arr[1]['search']['value'] . '%');
            }
            if($columnName_arr[2]['search']['value'] != null){
                $couriers=$couriers->Where('bank_branch_name', 'like', $columnName_arr[2]['search']['value'] . '%');
            }
            if($columnName_arr[3]['search']['value'] != null){
                $couriers=$couriers->Where('bank_branch_email', 'like', $columnName_arr[3]['search']['value'] . '%');
            }
            if($columnName_arr[4]['search']['value'] != null){
                $couriers=$couriers->Where('bank_branch_phone', 'like', $columnName_arr[4]['search']['value'] . '%');
            }
            if($columnName_arr[5]['search']['value'] != null){
                $couriers=$couriers->Where('bank_branch_mobile', 'like', $columnName_arr[5]['search']['value'] . '%');
            }
            if($columnName_arr[6]['search']['value'] != null){
                $couriers=$couriers->Where('bank_branch_address', 'like', $columnName_arr[6]['search']['value'] . '%');
            }
            
            if($columnName_arr[7]['search']['value'] != null){
                $couriers=$couriers->Where('bank_branches.status', 'like', $columnName_arr[7]['search']['value'] . '%');
            }
            // ->where('bank_branches.bank_branch_name', 'like', $searchValue . '%')
            // ->orWhere('banks.bank_name', 'like', $searchValue . '%')
            // ->orWhere('bank_branches.bank_branch_address', 'like', $searchValue . '%')
            // ->orWhere('bank_branches.bank_branch_email', 'like',$searchValue . '%')
            // ->orWhere('bank_branches.bank_branch_phone', 'like', $searchValue . '%')
            // ->orWhere('bank_branches.bank_branch_mobile', 'like', $searchValue . '%')

            if($rowperpage < 0) {
            $rowperpage = 8999999999999999999;
        }
            $couriers=$couriers->skip($start)
            ->take($rowperpage)
            ->get();
        $data_arr = array();
        foreach($couriers as $courier){

            $action ='<div role="group" aria-label="Basic example" class="btn-group btn-group-sm">';
            // if(auth()->user()->canEvent('edit_branch'))
            // {
                $action .='<a href="'.url('admin/edit_branch/'.$courier->bank_branch_id ).'" class="mr-2">
                                                            <i class="fa fa-edit text-warning"></i>
                                                        </a>';
            // }
            $action .='</div>';
          
                                               
            $data_arr[] = array(
                "bank_branch_id " => $courier->bank_branch_id ,
                "bank_name" => $courier->bank_name,
                "bank_branch_name" => $courier->bank_branch_name,
                "bank_branch_address" => $courier->bank_branch_address,
                "bank_branch_email" => $courier->bank_branch_email,
                "bank_branch_phone" => $courier->bank_branch_phone,
                "status" => $courier->status == 1 ? 'Active' : 'In Active',
                "bank_branch_mobile" => $courier->bank_branch_mobile,
                "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_branch'))
        // {
        //     return redirect('/');
        // }
        $banks = Bank::where('status',1)->get();
       return view('backend.bank_branch.create',['banks'=>$banks]);
    }
    public function get_branch_by_bank_id(Request $request){
        return BankBranch::where('bank_id',$request->bank_id)->get();
    }

    /**
     * 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(), [
            'bank_branch_name' => 'required|unique:bank_branches|max:150',
            'bank_branch_address' => 'required|max:150',
            'bank' => 'required',
            'bank_branch_email' => 'max:150',
            'bank_branch_phone' => 'max:20',
            'bank_branch_mobile' => 'max:20',
           
        ]);
        
        if ($validator->fails())
        {
            return response()->json(['errors'=>$validator->errors()->all()]);
        }else{
           //return  response()->json(['re'=> auth()->user()->user_id]);
            $bank =  new BankBranch;
            $bank->bank_branch_name = $request->bank_branch_name;
            $bank->bank_branch_address = $request->bank_branch_address;
            $bank->bank_id = $request->bank;
            $bank->bank_branch_phone = $request->bank_branch_phone;
            $bank->bank_branch_email = $request->bank_branch_email;
            $bank->bank_branch_mobile = $request->bank_branch_mobile;
            $bank->status = $request->status ? $request->status : 0;
            // $bank->created_by = auth()->user()->user_id;
            $bank->save();
        }
        return response()->json(['errors'=>'0','success'=> $request->bank_branch_name.' is successfully added']);
    }

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

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Models\BankBranch  $bankBranch
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        // if(!auth()->user()->canEvent('edit_branch'))
        // {
        //     return redirect('/');
        // }
        $banks=Bank::get();
        $branch = BankBranch::where('bank_branch_id',$id)->first();
       // dd($branch);
        
        return view('backend.bank_branch.edit',['banks'=>$banks,'branch'=>$branch]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\BankBranch  $bankBranch
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, BankBranch $bankBranch)
    {
       $id=$request->bank_branch_id;
       $validator = \Validator::make($request->all(), [
            'bank_branch_name' => 'required|max:150|unique:bank_branches,bank_branch_name,'.$id.',bank_branch_id',

            'bank_branch_address' => 'required|max:150',
            'bank_branch_email' => 'required|max:150',
            'bank_branch_phone' => 'required|max:20',
            'bank_branch_mobile' => 'required|max:20',
            'bank' => 'required',
           
        ]);
        
        if ($validator->fails())
        {
            return response()->json(['errors'=>$validator->errors()->all()]);
        }else{
           //return  response()->json(['re'=> auth()->user()->user_id]);
            $bank =  BankBranch::find($request->bank_branch_id );
            $bank->bank_branch_name = $request->bank_branch_name;
            $bank->bank_branch_address = $request->bank_branch_address;
            $bank->bank_branch_email = $request->bank_branch_email;
            $bank->bank_branch_phone = $request->bank_branch_phone;
            $bank->bank_branch_mobile = $request->bank_branch_mobile;
            $bank->status = $request->status ? $request->status : 0;
            $bank->bank_id = $request->bank;
            // $bank->updated_by = auth()->user()->user_id;
            $bank->save();
        }
        return response()->json(['errors'=>'0','success'=> $request->bank_branch_name.' is successfully Updated']);
    }

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

VaKeR 2022