HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/blijegasten/blijegasten.be/app/Komma/Shop/Shipments/ShipmentController.php
<?php

namespace App\Komma\Shop\Shipments;

use App\Helpers\KommaHelpers;
use App\Komma\Globalization\RegionInfo;
use App\Komma\Globalization\RegionInfoInterface;
use App\Komma\Kms\Core\Attributes\Models\Traits\HasThumbnailInterface;
use App\Komma\Kms\Core\Entities\DisplayNameInterface;
use App\Komma\Kms\Core\SectionController;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\MessageBag;

class ShipmentController extends SectionController
{
    protected $slug = "shipments";

    protected $classModelName = Shipment::class;
    /**
     * @var ShipmentService
     */
    private $shipmentService;

    public function __construct()
    {
        $section = new ShipmentSection($this->slug);
        $this->shipmentService = app(ShipmentService::class);
        parent::__construct($section);
    }

    /**
     * This method is called on the overview page.
     * It will render the section and view.
     *
     * @return mixed
     * @throws \Illuminate\Auth\Access\AuthorizationException
     */
    public function index()
    {
        $this->authorize('index', $this->classModelName);

        /** @var ShipmentSection $section */
        $section = $this->section;

        $shopRegionInfo = app(RegionInfoInterface::class);

        $amount = 20;
        $shipmentCollection = $this->shipmentService->getLatest($amount)->with(['shipmentGroup', 'order'])->get();

        $view = $this->renderShipmentIndex();
        $view->with('shipments', $shipmentCollection)
            ->with('shopRegionInfo', $shopRegionInfo)
            ->with('resultsTypeTranslation', __('shop/shipments.latest_shipments', ['amount' => $amount]));
        return $view;
    }

    /**
     * Search for orders
     *
     * @param SearchRequest $request
     * @return \Illuminate\Contracts\View\View|\Illuminate\Http\Resources\Json\AnonymousResourceCollection
     */
    public function shipmentSearch(SearchRequest $request)
    {
        $resultsPerPage = (is_numeric(Input::get('perPage')) ? (int) Input::get('perPage') : 5);
        $shipments = $this->shipmentService->search(Input::all())->orderBy('created_at', 'desc')->with('order')->paginate($resultsPerPage);
        $shipments->appends(Input::all()); //Add existing query string parameters to the current pagination links

        $shopRegionInfo = app(RegionInfoInterface::class);

        if(request()->ajax()) {
            //Return results as json
            //Make a ShipmentGroup json resource and return a collection of that if you need this functionality
        } else {
            $request->flash();

            $view = $this->renderShipmentIndex();
            return $view->with('shipments', $shipments)
                ->with('shopRegionInfo', $shopRegionInfo)
                ->with('perPage', $resultsPerPage)
                ->with('status', \Input::get('status'))
                ->with('resultsTypeTranslation', __('shop/orders.search_results'));
        }
    }


    /**
     * For the index controller action
     *
     * @return View
     */
    public function renderShipmentIndex() {
        $modelId = ($this->forModelInstance) ? $this->forModelInstance->id : null;
        $saveRoute = $this->routeService->getSaveRoute($this->slug, $modelId);

        $successes = (Session::has('successes')) ? Session::get('successes') : new MessageBag();

        return view('kms/shop/shipments/index', [
            'siteSlug'                     => !$this->siteService->getCurrentSite()->exists ? null : $this->siteService->getCurrentSite()->slug,
            'section'                      => $this,
            'showEntity'                   => $this->showEntity,
            'slug'                         => $this->slug,
            'saveRoute'                    => $saveRoute,
            'successes'                    => $successes,
            'maxUploadSize'                => KommaHelpers::fileUploadMaxSize(),
            'maxPostSize'                  => KommaHelpers::maxPostSize(),
            'preventNavigationTranslation' => json_encode(__('kms/prevent-navigation'))
        ]);
    }

    /**
     * Makes a full width view. The sidebar is not needed
     *
     * @return View
     */
    protected function makeView(): View
    {
        $thumbnail = '';
        if(is_a($this->forModelInstance, HasThumbnailInterface::class)) {
            $thumbnail = $this->forModelInstance->getThumbnail();
        };

        if(is_a($this->forModelInstance, DisplayNameInterface::class)) {
            $displayName = $this->forModelInstance->getDisplayName();
        } else {
            $displayName = $this->section->getSectionNewModel();
        }

        $modelId = ($this->forModelInstance) ? $this->forModelInstance->id : null;
        $saveRoute = $this->routeService->getSaveRoute($this->slug, $modelId);

        $successes = (Session::has('successes')) ? Session::get('successes') : new MessageBag();

        return view('kms/section.fullwidth', [
            'siteSlug'                     => !$this->siteService->getCurrentSite()->exists ? null : $this->siteService->getCurrentSite()->slug,
            'section'                      => $this,
            'showEntity'                   => $this->showEntity,
            'slug'                         => $this->slug,
            'saveRoute'                    => $saveRoute,
            'successes'                    => $successes,
            'thumbnail'                    => $thumbnail,
            'displayName'                  => $displayName,
            'modelClassName'                 => $this->classModelName,
            'submitButtonLabel'            => $this->section->getSubmitButtonLabel(),
            'currentModel'                 => $this->forModelInstance,
            'sectionTabs'                  => $this->section->getTabs(),
            'maxUploadSize'                => KommaHelpers::fileUploadMaxSize(),
            'maxPostSize'                  => KommaHelpers::maxPostSize(),
            'preventNavigationTranslation' => json_encode(__('kms/prevent-navigation')),
        ]);
    }
}