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/SBogers10/bomacon.komma.pro/app/Http/Wildcards/ServicesWildcard.php
<?php

namespace App\Http\Wildcards;

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

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

        // Check if the first segment is found in the ServiceTranslation
        // If ServiceTranslation isn't found then send to the filters method
        if($serviceTranslation = ServiceTranslation::where('slug', $tail)->first())
        {
            //Set the request URI and the original path
            $request->server->set('REQUEST_URI', 'services/'.$serviceTranslation->service_id);
            return $request;
        }

        // Bind filters to the request and set uri to the filter function of the service controller
        $request->merge(['filters' => $tail]);

        //Set the request URI and the original path
        $request->server->set('REQUEST_URI', 'services/filters');

        return $request;
    }

}