File: D:/HostingSpaces/SBogers10/bomacon.komma.pro/app/Http/Wildcards/MachinesWildcard.php
<?php
namespace App\Http\Wildcards;
use App\Machines\Models\MachineTranslation;
use Illuminate\Http\Request;
class MachinesWildcard 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 MachineTranslation
// If MachineTranslation isn't found then send to the filters method
if($machineTranslation = MachineTranslation::where('slug', $tail)->first())
{
//Set the request URI and the original path
$request->server->set('REQUEST_URI', 'machines/'.$machineTranslation->machine_id);
return $request;
}
// Bind filters to the request and set uri to the filter function of the machine controller
$request->merge(['filters' => $tail]);
//Set the request URI and the original path
$request->server->set('REQUEST_URI', 'machines/filters');
return $request;
}
}