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/Neopoints/momsecurity.be/app/Http/Wildcards/ServicesWildcard.php
<?php

namespace App\Http\Wildcards;

use App\Services\Models\Service;
use App\Services\Models\ServiceTranslation;
use Illuminate\Http\Request;

class ServicesWildcard implements WildcardInterface
{
    /**
     * @param Request $request
     * @param $route
     * @param string $tail
     * @return Request
     */
    public function handle(Request $request, $route, string $tail): Request
    {

        if($route->route == 'pages/4') $serviceType = 0;
        else $serviceType = 1;

        $serviceTypeIds = Service::where('service_type', $serviceType)
            ->where('active', 1)
            ->get()
            ->pluck('id')
            ->toArray();

        // Check if the first segment is found in the TranslatableModel
        $modelTranslation = ServiceTranslation::where('language_id', app()->getLanguage()->id)
            ->where('slug', $tail)
            ->whereIn('service_id', $serviceTypeIds)
            ->first();

        // If found then send to the show method
        if($modelTranslation)
        {
            //Set the request URI and the original path
            $request->server->set('REQUEST_URI', 'services/' . $modelTranslation->service_id);
            return $request;
        }

        return $request;
    }

}