ldc-doux/app/Providers/RouteServiceProvider.php
2022-08-11 12:34:27 +02:00

48 lines
1.4 KiB
PHP

<?php
namespace App\Providers;
use App\Models\Gamme;
use App\Models\Product;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
/**
* The path to the "home" route for your application.
*
* This is used by Laravel authentication to redirect users after login.
*
* @var string
*/
public const HOME = '/bo';
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot()
{
$this->routes(function () {
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
});
//phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
Route::bind('gammeSlug', function ($value, $route) {
$gamme = Gamme::where('slug', 'LIKE', '%:"' . $value . '"%')->firstOrFail();
return $gamme;
});
Route::bind('productSlug', function ($value, $route) {
$gamme = $route->parameter('gammeSlug');
$product = Product::where('slug', 'LIKE', '%:"' . $value . '"%')
->where('gamme_id', $gamme->id)
->firstOrFail();
return $product;
});
}
}