where('id', $value)->orWhere('slug', $value); })->where('status', true)->firstOrFail(); }); Route::bind('publishedActu', function ($value) { return Actu::where(function ($q) use ($value) { $q->where('id', $value)->orWhere('slug', $value); })->where('status', true)->firstOrFail(); }); Route::model('breedingPageType', BreedingPageType::class); Route::bind('publishedBreedingPage', function ($value) { // * Old slug middleware will throw 404 if needed. return BreedingPage::where('slug', $value)->whereStatus(true)->first() ?? $value; }); Route::bind('articleTag', function ($value) { try { return ArticleCategory::make($value); } catch (BadMethodCallException | EnumNotRoutableException $e) { // handle old article route $publishedArticle = Articles::where('id', $value) ->orWhere('slug', $value)->where('status', true)->first(); if ($publishedArticle) { // redirect permanent, throw redirect exception using send method \redirect(route('club.infos.child', [ 'articleTag' => $publishedArticle->type, 'publishedArticle' => $publishedArticle ]), 301)->send(); } else { abort(404); } } }); Route::model('engagement', Engagement::class); Route::bind('publishedProduct', function ($value) { // * Old slug middleware will throw 404 if needed. return Products::where('slug', $value)->where('status', true)->first() ?? $value; }); Route::bind('product', function ($value) { return Products::where('id', $value)->firstOrFail(); }); Route::bind('range', function ($value) { return Range::where('id', $value)->orWhere('slug', $value)->firstOrFail(); }); Route::bind('moment', function ($value) { return Moments::where('id', $value)->orWhere('slug', $value)->firstOrFail(); }); Route::bind('slugSubRange', function ($value, RoutingRoute $route) { // * slugRange must be resolved since slugSubRange comes second on url. /** @var \App\Models\Range */ $slugRange = $route->parameter('slugRange'); return SubRange::whereSlug($value)->whereHas('ranges', function (Builder $q) use ($slugRange) { $q->where('id', $slugRange->id); })->firstOrFail(); }); Route::bind('subRange', function ($value) { return SubRange::where('id', $value)->firstOrFail(); }); Route::bind('slugRange', function ($value) { return Range::where('slug', $value)->where('status', true)->firstOrFail(); }); Route::bind('slugConsumptionTime', function ($value) { return ConsumptionTimes::where('slug', $value)->where('status', true)->firstOrFail(); }); Route::bind('slugMeatType', function ($value) { return MeatTypes::where('slug', $value)->where('status', true)->firstOrFail(); }); Route::bind('slugLabel', function ($value) { return Label::where('slug', $value)->where('status', true)->firstOrFail(); }); Route::bind('consumptiontime', function ($value) { return ConsumptionTimes::where('id', $value)->orWhere('slug', $value)->firstOrFail(); }); Route::bind('meat_type', function ($value) { return MeatTypes::where('id', $value)->orWhere('slug', $value)->firstOrFail(); }); Route::bind('label', function ($value) { return Label::where('id', $value)->firstOrFail(); }); Route::bind('ocbbreeder', function ($value) { return OCBBreeder::where('id', $value)->orWhere('slug', $value)->firstOrFail(); }); Route::model('ad', Ads::class); Route::model('homeslider', HomeSliderPictures::class); Route::model('newsslider', NewsSliderPictures::class); Route::model('productslider', ProductSliderPictures::class); Route::bind('recipe', function ($value) { return Recipes::where('id', $value)->orWhere('slug', $value)->firstOrFail(); }); Route::bind('actu', function ($value) { return Actu::where('id', $value)->orWhere('slug', $value)->firstOrFail(); }); Route::bind('article', function ($value) { return Articles::where('id', $value)->orWhere('slug', $value)->firstOrFail(); }); Route::model('faq_question', FaqQuestions::class); Route::model('breederportrait', BreederPortrait::class); Route::model('nutrition_page', NutritionPage::class); Route::model('poultry_page', PoultryPage::class); Route::model('dans_les_pre', DansLesPresContent::class); Route::model('ocb', OCBContent::class); Route::model('tag', Tag::class); Route::model('breeding_page', BreedingPage::class); Route::model('reduction', Reduction::class); Route::bind('general_config', function ($value) { try { $value = \ctype_digit($value) ? \intval($value) : $value; foreach (GeneralConfigType::toArray() as $config) { if ($config->value === $value) { return GeneralConfig::where('type', $value)->firstOrFail(); } } abort(404); } catch (BadMethodCallException | EnumNotRoutableException $e) { return null; } }); parent::boot(); } /** * Define the routes for the application. * * @return void */ public function map() { $this->mapApiRoutes(); $this->mapWebRoutes(); } /** * Define the "web" routes for the application. * * These routes all receive session state, CSRF protection, etc. * * @return void */ protected function mapWebRoutes() { Route::middleware('web') ->namespace($this->namespace) ->group(base_path('routes/web.php')); } /** * Define the "api" routes for the application. * * These routes are typically stateless. * * @return void */ protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) ->group(base_path('routes/api.php')); } }