Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/mcoil.corals.io/app/Http/Controllers/Admin/Addresses/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/mcoil.corals.io/app/Http/Controllers/Admin/Addresses/AddressController.php
<?php

namespace App\Http\Controllers\Admin\Addresses;

use App\Shop\Addresses\Address;
use App\Shop\Addresses\Repositories\AddressRepository;
use App\Shop\Addresses\Repositories\Interfaces\AddressRepositoryInterface;
use App\Shop\Addresses\Requests\CreateAddressRequest;
use App\Shop\Addresses\Requests\UpdateAddressRequest;
use App\Shop\Addresses\Transformations\AddressTransformable;
use App\Shop\Cities\City;
use App\Shop\Cities\Repositories\Interfaces\CityRepositoryInterface;
use App\Shop\Countries\Country;
use App\Shop\Countries\Repositories\CountryRepository;
use App\Shop\Countries\Repositories\Interfaces\CountryRepositoryInterface;
use App\Shop\Customers\Repositories\Interfaces\CustomerRepositoryInterface;
use App\Http\Controllers\Controller;
use App\Shop\Provinces\Repositories\Interfaces\ProvinceRepositoryInterface;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class AddressController extends Controller
{
    use AddressTransformable;

    private $addressRepo;
    private $customerRepo;
    private $countryRepo;
    private $provinceRepo;
    private $cityRepo;

    public function __construct(
        AddressRepositoryInterface $addressRepository,
        CustomerRepositoryInterface $customerRepository,
        CountryRepositoryInterface $countryRepository,
        ProvinceRepositoryInterface $provinceRepository,
        CityRepositoryInterface $cityRepository
    ) {
        $this->addressRepo = $addressRepository;
        $this->customerRepo = $customerRepository;
        $this->countryRepo = $countryRepository;
        $this->provinceRepo = $provinceRepository;
        $this->cityRepo = $cityRepository;
    }

    /**
     * Display a listing of the resource.
     *
     * @param Request $request
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request) {
        return view('admin.addresses.list');
    }
    
    public function serverSidePagination(Request $request){
        $columns = array( 
                            0 =>'address_1', 
                            1 =>'name',
                            2=> 'billing_type_address',
                            3=> 'town',
                            4=> 'county',
                            5=> 'eircode',
                            6=>'phone',
                            7=>'status',
                            8=>'actions'
                           
                           
                        );
        $start = $request->input('start');
        $limit = $request->input('length');
        if($columns[$request->input('order.0.column')] == 'name'){
             $order = 'customers.'.$columns[$request->input('order.0.column')];
        }else{
            $order = 'addresses.'.$columns[$request->input('order.0.column')];
        }
       
        $dir = $request->input('order.0.dir');
        $data =[];
        $totalData = Address::count();
        $totalFiltered = $totalData;
        if(empty($request->input('search.value'))){
            $list = Address::leftJoin('customers','customers.id','=','addresses.customer_id')
            ->select('addresses.*','customers.name')
            ->offset($start)
                         ->limit($limit)->orderBy($order,$dir)->get();
            if(count($list) > 0){
                foreach($list as $address){
                    $edit = route('admin.addresses.edit', $address->id);
                    $cust_add =  url('/admin/customers/' . $address->customer_id);
                    $destroy = route('admin.addresses.destroy', $address->id);
                    $add = $address->address_1;
                    if ($address->address_2){
                     $add = $add.', '.$address->address_2;
                    }
                    if($address->billing_type_address == '1'){
                        $add_type = 'Billing';
                    }else{
                        $add_type = 'Delivery';   
                    }
                     if($address->status != '1'){
                        $status = '<span class="badge font-badge badge-danger">disabled</span>';
                    }else{
                        $status = '<span class="badge font-badge badge-success">enabled</span>';
                    }
                    $csrf_token = csrf_field();
                    if($address->billing_type_address == 1){
                        $btn = "<button type='button' class='btn btn-danger btn_delete_address' disabled><i class='fa fa-times'></i> Delete</button";
                    }else{
                         $btn = "<button type='button' class='btn btn-danger btn_delete_address' ><i class='fa fa-times'></i> Delete</button";
                    }
                    $actions = "<form action='{$destroy}' method='post' class='form-horizontal frm_delete_address'><input type='hidden' name='_token' value='{$csrf_token}' /> <input type='hidden' name='_method' value='delete'><div class='btn-group flex-wrap'>
                        <a href='{$edit}' class='btn btn-dark'><i class='fa fa-pencil'></i> Edit</a>
                        ".$btn."</div></form>";
                    $nestedData['address_1'] = "<a href='{$edit}'>".$add."</a>";
                    $nestedData['name'] =  "<a href='{$cust_add}'>".$address->name."</a>";
                    $nestedData['billing_type_address'] = $add_type;
                    $nestedData['town'] = $address->town;
                    $nestedData['county'] = $address->county;
                    $nestedData['eircode'] = $address->zip;
                    $nestedData['phone'] = $address->phone;
                    $nestedData['status'] = $status;
                    
                    $nestedData['actions'] = $actions;
                    $data[] = $nestedData;
                }
            }
        }
        else{
             $search = $request->input('search.value');
             $list = Address::leftJoin('customers','customers.id','=','addresses.customer_id')
            ->select('addresses.*','customers.name');
             $list = $list->where(function($query) use($search){
                $query->where('addresses.address_1','LIKE','%'.$search.'%')
                ->orWhere('addresses.address_2','LIKE','%'.$search.'%')
                ->orWhere('customers.name','LIKE','%'.$search.'%')
                ->orWhere('addresses.town','LIKE','%'.$search.'%')
                ->orWhere('addresses.county','LIKE','%'.$search.'%')
                 ->orWhere('addresses.zip','LIKE','%'.$search.'%')
                 ->orWhere('addresses.phone','LIKE','%'.$search.'%')
                  ;
            });
             $totalFiltered = $list->count();
            $list = $list->offset($start)
                         ->limit($limit)->orderBy($order,$dir)->get();
            if(count($list) > 0){
                foreach($list as $address){
                    $edit = route('admin.addresses.edit', $address->id);
                    $cust_add =  url('/admin/customers/' . $address->customer_id);
                    $destroy = route('admin.addresses.destroy', $address->id);
                    $add = $address->address_1;
                    if ($address->address_2){
                     $add = $add.', '.$address->address_2;
                    }
                    if($address->billing_type_address == '1'){
                        $add_type = 'Billing';
                    }else{
                        $add_type = 'Delivery';   
                    }
                     if($address->status != '1'){
                        $status = '<span class="badge font-badge badge-danger">disabled</span>';
                    }else{
                        $status = '<span class="badge font-badge badge-success">enabled</span>';
                    }
                    $csrf_token = csrf_field();
                    if($address->billing_type_address == 1){
                        $btn = "<button type='button' class='btn btn-danger btn_delete_address' disabled><i class='fa fa-times'></i> Delete</button";
                    }else{
                         $btn = "<button type='button' class='btn btn-danger btn_delete_address' ><i class='fa fa-times'></i> Delete</button";
                    }
                    $actions = "<form action='{$destroy}' method='post' class='form-horizontal frm_delete_address'><input type='hidden' name='_token' value='{$csrf_token}' /> <input type='hidden' name='_method' value='delete'><div class='btn-group flex-wrap'>
                        <a href='{$edit}' class='btn btn-dark'><i class='fa fa-pencil'></i> Edit</a>
                        ".$btn."</div></form>";
                    $nestedData['address_1'] = "<a href='{$edit}'>".$add."</a>";
                    $nestedData['name'] =  "<a href='{$cust_add}'>".$address->name."</a>";
                    $nestedData['billing_type_address'] = $add_type;
                    $nestedData['town'] = $address->town;
                    $nestedData['county'] = $address->county;
                    $nestedData['eircode'] = $address->zip;
                    $nestedData['phone'] = $address->phone;
                    $nestedData['status'] = $status;
                    
                    $nestedData['actions'] = $actions;
                    $data[] = $nestedData;
                }
            }
        }
        $json_data = array(
                    "draw"            => intval($request->input('draw')),  
                    "recordsTotal"    => intval($totalData),  
                    "recordsFiltered" => intval($totalFiltered), 
                    "data"            => $data   
                    );
            
        echo json_encode($json_data); 
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create() {
        $countries = $this->countryRepo->listCountries();
        $country = $this->countryRepo->findCountryById(1);
        $customers = $this->customerRepo->listCustomers();
        return view('admin.addresses.create', [
            'customers' => $customers,
            'countries' => $countries,
            'provinces' => $country->provinces,
            'cities' => City::all()
        ]);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  CreateAddressRequest $request
     * @return \Illuminate\Http\Response
     */
    public function store(CreateAddressRequest $request) {
        $this->addressRepo->createAddress($request->except('_token', '_method'));
        return redirect()->route('admin.addresses.index')->with('message', 'Address added successfully.');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show(int $id) {
        return view('admin.addresses.show', ['address' => $this->addressRepo->findAddressById($id)]);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit(int $id) {
        $countries = $this->countryRepo->listCountries();
        $country = $countries->filter(function ($country) {
            return $country == env('SHOP_COUNTRY_ID', '1');
        })->first();
        $countryRepo = new CountryRepository(new Country);
        if (!empty($country)) {
            $countryRepo = new CountryRepository($country);
        }
        $address = $this->addressRepo->findAddressById($id);
        $addressRepo = new AddressRepository($address);
        $customer = $addressRepo->findCustomer();
        return view('admin.addresses.edit', [
            'address' => $address,
            'countries' => $countries,
            'countryId' => $address->country->id,
            'provinces' => $countryRepo->findProvinces(),
            'cities' => $this->cityRepo->listCities(),
            'cityId' => $address->city_id,
            'customers' => $this->customerRepo->listCustomers(),
            'customerId' => $customer->id
        ]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  UpdateAddressRequest $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(UpdateAddressRequest $request, $id) {
    	$address = $this->addressRepo->findAddressById($id);
    	$update = new AddressRepository($address);
        $update->updateAddress($request->except('_method', '_token'));
        // Update the phone in user table also if the address type is billing
        if ($address->billing_type_address == '1') {
	        $phone = $request->get('phone');
	        $customerId = $request->get('customer');
	        $customer = DB::table('customers')->where('id', $customerId)->update(['phone' => $phone]);
        }
        return redirect()->route('admin.addresses.index')->with('message', 'Address updated successfully.');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id) {
        $address = $this->addressRepo->findAddressById($id);
        $delete = new AddressRepository($address);
        $delete->deleteAddress();
        return redirect()->back();
    }
}

Spamworldpro Mini