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/stafa/werkenbijstafa.nl/app/Komma/Shop/Shipments/ShipmentController.php
<?php

namespace App\Komma\Shop\Shipments;

use App\Komma\Globalization\RegionInfo;
use App\Komma\Kms\Core\SectionController;
use App\Komma\Shop\Shipments\Shipment;
use Illuminate\Support\Facades\Input;

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

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

    public function __construct(ShipmentSection $section, ShipmentService $shipmentService)
    {
        parent::__construct($section);
        $this->shipmentService = $shipmentService;
    }

    /**
     * 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->forModelName);

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

        $shopRegionInfo = new RegionInfo('NL'); //Shop was build with euros in mind and the Dutch language as the primary one

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

        $section->setForModelName($this->forModelName);

        $view = $section->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 = new RegionInfo('NL'); //Shop was build with euros in mind and the Dutch language as the primary one

        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();

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

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