HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/www.shooperm.com/Modules/Shipping/Http/Controllers/ShippingController.php
<?php

namespace Modules\Shipping\Http\Controllers;

use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\Shipping\Repositories\CarrierRepository;
use Modules\Shipping\Services\ShippingService;
use Modules\Shipping\Http\Requests\CreateShippingRequest;
use Brian2694\Toastr\Facades\Toastr;
use Exception;
use Modules\Shipping\Http\Requests\UpdateShippingRequest;
use Modules\UserActivityLog\Traits\LogActivity;

class ShippingController extends Controller
{
    protected $shippingService;

    public function __construct(ShippingService  $shippingService)
    {
        $this->middleware('maintenance_mode');
        $this->shippingService = $shippingService;
    }

    public function index()
    {
        $data['methods'] = $this->shippingService->getAll();
        $carrierRepo = new CarrierRepository();
        $data['carriers'] = $carrierRepo->getActiveAll();
        return view('shipping::shipping_methods.index', $data);
    }

    public function store(CreateShippingRequest $request)
    {
        try {
            $this->shippingService->store($request->except("_token"));
            LogActivity::successLog('New Shipping method added');
            return $this->reloadWithData();
        } catch (\Exception $e) {
            LogActivity::errorLog($e->getMessage());
            Toastr::error(__('common.Something Went Wrong'));
            return response()->json([
                'error' => $e->getMessage()
            ],500);
        }
    }

    public function edit($id)
    {

        $shipping_method = $this->shippingService->findById($id);
        if(auth()->user()->role->type == 'seller' && $shipping_method->request_by_user != auth()->user()->id){
            Toastr::error(__('common.Something Went Wrong'));
            return false;
        }

        $carrierRepo = new CarrierRepository();
        $carriers = $carrierRepo->getActiveAll();
        return view('shipping::shipping_methods.components._edit',compact('shipping_method','carriers'));
    }

    public function update(UpdateShippingRequest $request)
    {

        try {
            $this->shippingService->update($request->except("_token"), $request->id);
            LogActivity::successLog('Shipping method Updated');
            return $this->reloadWithData();
        } catch (\Exception $e) {
            LogActivity::errorLog($e->getMessage());
            Toastr::error(__('common.Something Went Wrong'));
            return response()->json([
                'error' => $e->getMessage()
            ],503);
        }
    }


    public function destroy(Request $request)
    {
        try {
            $result = $this->shippingService->delete($request->id);
            if ($result == "invalid") {
                return response()->json([
                    'msg' => __('Invalid Request.')
                ]);
            }
            elseif ($result == "not_possible") {
                return response()->json([
                    'msg' => __('common.related_data_exist_in_multiple_directory')
                ]);
            }
            elseif ($result == "not_possible_for_1") {
                return response()->json([
                    'msg' => __('Last Shipping Rate Is Not Deletable.')
                ]);
            }else{
                LogActivity::successLog('Shipping Method has been destroyed.');
                return $this->reloadWithData();
            }
        } catch (\Exception $e) {
            LogActivity::errorLog($e->getMessage());
            Toastr::error(__('common.Something Went Wrong'));
            return response()->json([
                'error' => $e->getMessage()
            ],503);
        }
    }


    public function update_status(Request $request)
    {
        try {
            $this->shippingService->updateStatus($request->except("_token"));
            return 1;
        } catch (\Exception $e) {
            LogActivity::errorLog($e->getMessage());
            return 0;
        }
    }

    public function update_approve_status(Request $request)
    {
        try {
            $this->shippingService->updateApproveStatus($request->except("_token"));
            return 1;
        } catch (\Exception $e) {
            LogActivity::errorLog($e->getMessage());
            return 0;
        }
    }


    private function reloadWithData(){
        try{
            $carrierRepo = new CarrierRepository();
            $carriers = $carrierRepo->getActiveAll();
            $methods = $this->shippingService->getAll();
            return response()->json([

                'TableData' =>  (string)view('shipping::shipping_methods.components._method_list', compact('methods','carriers')),
                'createForm' =>  (string)view('shipping::shipping_methods.components._create',compact('carriers'))
            ],200);
        }catch(Exception $e){
            LogActivity::errorLog($e->getMessage());
            Toastr::error($e->getMessage(), 'Error!!');
            return response()->json([
                'error' => $e->getMessage()
            ],503);
        }
    }
}