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/SBogers95/rentman.io/app/Komma/CustomerLogos/CustomerLogoController.php
<?php

namespace App\Komma\CustomerLogos;

use App\Http\Controllers\Controller;
use App\Komma\Countries\CountryService;
use App\Komma\CustomerLogos\Resources\CustomerLogoSliderResource;
use Illuminate\Support\Facades\Log;

final class CustomerLogoController extends Controller
{
    private $customerLogoService;

    const MAX_AMOUNT_EACH_REQUEST = 10;

    public function __construct()
    {
        parent::__construct();
        $this->customerLogoService = \App::make(CustomerLogoService::class);
    }

    public function getCustomerLogosByCountry()
    {
        $countryService = app(CountryService::class);

        $country = $countryService->getCountryByIp();

        if (! $country) {
            Log::warning('CustomerLogoController@getCustomerLogosByCountry: No country found by IP');

            return response(null, 204);
        }

        Log::info('CustomerLogoController@getCustomerLogosByCountry: Found country is '.$country->iso_2);

        if (request()->input('limit') == 0) {
            $customerLogos = $this->customerLogoService->getCustomerLogosByCountry($country, 999999);
        } elseif (request()->input('limit') !== null) {
            $customerLogos = $this->customerLogoService->getCustomerLogosByCountry($country, request()->input('limit'));
        } else {
            $customerLogos = $this->customerLogoService->getCustomerLogosByCountry($country, self::MAX_AMOUNT_EACH_REQUEST);
        }

        if ($customerLogos->isEmpty()) {
            return response(null, 204);
        }

        return CustomerLogoSliderResource::collection($customerLogos)
            ->additional(['country' => [
                'id' => $country->id,
                'iso_2' => $country->iso_2,
                'name' => $country->name,
            ]]);
    }

    public function getCustomerLogosByCountryWhereNotIn()
    {
        Log::info('hoi');

        $loadedIds = \Input::post('ids');

        $countryService = app(CountryService::class);

        $country = $countryService->getCountryByIp();

        if (! $country) {
            Log::warning('CustomerLogoController@getCustomerLogosByCountryWhereNotIn: No country found by IP');

            return response(null, 204);
        }

        Log::info('CustomerLogoController@getCustomerLogosByCountryWhereNotIn: Found country is '.$country->iso_2);

        $customerLogos = $this->customerLogoService->getCustomerLogosByCountry($country, self::MAX_AMOUNT_EACH_REQUEST, $loadedIds);

        if ($customerLogos->isEmpty()) {
            return response(null, 204);
        }

        return CustomerLogoSliderResource::collection($customerLogos);
    }
}