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/zelfverkopen.komma.pro/app/Http/Wildcards/PropertiesWildcard.php
<?php

namespace App\Http\Wildcards;

use App\KommaApp\Realworks\Models\RealworkObject;

class PropertiesWildcard implements WildcardInterface
{

    /**
     * @param $request
     * @param $wildcard
     * @return mixed
     */
    public function handle($request, $wildcard)
    {
        // Property route should only have one tail
        if(sizeof($wildcard->tail) != 1) return $request;

        // Explode and grep the second segment
        $propertySlugParameters = explode('-', $wildcard->tail[0]);
        if(sizeof($propertySlugParameters) <= 1) return $request;
        $propertySystemId = $propertySlugParameters[1];

        // Check if for the system id
        if($object = RealworkObject::where('system_id', $propertySystemId)->first())
        {

            //Set the request URI and the original path
            $request->server->set('REQUEST_URI', 'properties/'.$object->id);
            return $request;
        }

        return $request;
    }

}