ldc-legaulois/app/Providers/RouteServiceProvider.php

211 lines
7.5 KiB
PHP
Raw Normal View History

2020-07-23 10:29:36 +02:00
<?php
namespace App\Providers;
use App\Enums\ArticleCategory;
use App\Enums\BreedingPageType;
2021-09-20 16:19:42 +02:00
use App\Enums\GeneralConfigType;
use App\Models\Actu;
2021-04-28 13:57:12 +02:00
use App\Models\Ads;
2021-03-05 08:17:35 +01:00
use App\Models\Articles;
2021-04-28 13:57:12 +02:00
use App\Models\BreederPortrait;
use App\Models\BreedingPage;
2021-04-28 13:57:12 +02:00
use App\Models\ConsumptionTimes;
use App\Models\Engagement;
2021-04-28 13:57:12 +02:00
use App\Models\FaqQuestions;
2021-09-20 16:19:42 +02:00
use App\Models\GeneralConfig;
2021-04-28 13:57:12 +02:00
use App\Models\HomeSliderPictures;
2021-11-16 16:00:47 +01:00
use App\Models\Label;
2021-04-28 13:57:12 +02:00
use App\Models\MeatTypes;
use App\Models\Moments;
use App\Models\NewsSliderPictures;
use App\Models\NutritionPage;
2021-04-28 13:57:12 +02:00
use App\Models\OCBBreeder;
use App\Models\OCBContent;
use App\Models\PoultryPage;
2021-03-21 22:51:19 +01:00
use App\Models\Products;
2021-04-28 13:57:12 +02:00
use App\Models\ProductSliderPictures;
2021-09-21 09:26:21 +02:00
use App\Models\Range;
2021-04-28 13:57:12 +02:00
use App\Models\Recipes;
2021-10-13 12:06:41 +02:00
use App\Models\Reduction;
use App\Models\SubRange;
2021-09-20 20:58:26 +02:00
use App\Models\Tag;
use BadMethodCallException;
2020-07-23 10:29:36 +02:00
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
use Kwaadpepper\Enum\Exceptions\EnumNotRoutableException;
2020-07-23 10:29:36 +02:00
class RouteServiceProvider extends ServiceProvider
{
/**
* This namespace is applied to your controller routes.
*
* In addition, it is set as the URL generator's root namespace.
*
* @var string
*/
protected $namespace = 'App\Http\Controllers';
/**
* The path to the "home" route for your application.
*
* @var string
*/
2021-04-28 13:57:12 +02:00
public const HOME = '/bo';
2020-07-23 10:29:36 +02:00
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot()
{
2021-03-05 08:17:35 +01:00
Route::bind('publishedArticle', function ($value) {
2021-09-17 22:18:39 +02:00
return Articles::where(function ($q) use ($value) {
$q->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();
2021-03-05 08:17:35 +01:00
});
2021-10-22 11:07:30 +02:00
Route::bind('publishedBreedingPage', function ($value) {
return BreedingPage::where('slug', $value)->whereStatus(true)->firstOrFail();
});
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);
2021-03-21 22:51:19 +01:00
Route::bind('product', function ($value) {
return Products::where('id', $value)->orWhere('slug', $value)->firstOrFail();
});
2021-04-28 13:57:12 +02:00
Route::bind('range', function ($value) {
2021-09-21 09:26:21 +02:00
return Range::where('id', $value)->orWhere('slug', $value)->firstOrFail();
2021-04-28 13:57:12 +02:00
});
Route::bind('moment', function ($value) {
return Moments::where('id', $value)->orWhere('slug', $value)->firstOrFail();
});
Route::bind('subRange', function ($value) {
return SubRange::where('id', $value)->orWhere('slug', $value)->firstOrFail();
2021-04-28 13:57:12 +02:00
});
Route::bind('slugRange', function ($value) {
2021-09-21 09:26:21 +02:00
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();
});
2021-11-22 15:02:18 +01:00
Route::bind('slugLabel', function ($value) {
return Label::where('slug', $value)->where('status', true)->firstOrFail();
});
2021-04-28 13:57:12 +02:00
Route::bind('consumptiontime', function ($value) {
return ConsumptionTimes::where('id', $value)->orWhere('slug', $value)->firstOrFail();
});
2021-05-01 08:53:35 +02:00
Route::bind('meat_type', function ($value) {
return MeatTypes::where('id', $value)->orWhere('slug', $value)->firstOrFail();
});
2021-11-16 16:00:47 +01:00
Route::bind('label', function ($value) {
2021-11-22 15:02:18 +01:00
return Label::where('id', $value)->firstOrFail();
2021-11-16 16:00:47 +01:00
});
2021-04-28 13:57:12 +02:00
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);
2021-04-28 13:57:12 +02:00
Route::bind('recipe', function ($value) {
return Recipes::where('id', $value)->orWhere('slug', $value)->firstOrFail();
});
2021-09-20 18:41:41 +02:00
Route::bind('actu', function ($value) {
return Actu::where('id', $value)->orWhere('slug', $value)->firstOrFail();
});
2021-04-28 13:57:12 +02:00
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('ocb', OCBContent::class);
2021-09-20 20:58:26 +02:00
Route::model('tag', Tag::class);
Ticket 689 Squashed commit of the following: commit e3861caa2e7046123be8adb2355e6c8b36e75f42 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Thu Mar 10 16:16:47 2022 +0100 Ticket689 : fix banner/title articles on breeding page commit 74a0c75844904b0639a86ed24c5ab9bfeedcd050 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Thu Mar 10 16:12:40 2022 +0100 Ticket677 : add migration for imgs on breeding page commit 48360d764cfb6de74d4c48ba3e5fe6def02ee673 Merge: 0eda4880 a120f51e Author: Olivier Legat <olivier.legat@ldc.fr> Date: Wed Mar 9 12:05:29 2022 +0000 Merge branch 'ticket689' of https://voight001.lesidc.com/legaulois2020 into ticket689 commit 0eda4880a9a39947009eb6137f2d493aa8cbfe4c Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Mon Mar 7 11:46:17 2022 +0100 Ticket 677 : add json key 'alt' in mini-crud commit e80793ebb6efab07147200ad8b072eccca366624 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:42:35 2022 +0100 add drop-down breeding menu in main header commit 5f406faf0f961456f776969858fa95b80b15388d Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:40:33 2022 +0100 supp header articles breeding pages commit 89e129fcde9230912a26ccf0cdbe87e8a3a60c63 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:39:53 2022 +0100 fix title/banner breeding pages commit c4688e28870a228b38ecc13091296e0005e0e04a Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Thu Mar 3 12:56:42 2022 +0100 adds breadcrumb on breeding pages (index, list, show) commit a120f51eb42c8a79b92cf41255026597179dd23e Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Mon Mar 7 11:46:17 2022 +0100 Ticket 677 : add json key 'alt' in mini-crud commit 3d5c8a6251abb7a45ac6b3db777b8837aa64f2bf Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:42:35 2022 +0100 add drop-down breeding menu in main header commit bc6f67f4a340488eed2d86b198bd79e1541649e5 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:40:33 2022 +0100 supp header articles breeding pages commit 3493c2806696c4ff1321fadb08a1648fd4704e40 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:39:53 2022 +0100 fix title/banner breeding pages commit d7c63486ecdc0f91b7fb8d4a5a851e4b1e9fdc10 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Thu Mar 3 12:56:42 2022 +0100 adds breadcrumb on breeding pages (index, list, show)
2022-03-14 14:09:43 +00:00
Route::model('breedingPageType', BreedingPageType::class);
Route::model('breeding_page', BreedingPage::class);
2021-10-13 12:06:41 +02:00
Route::model('reduction', Reduction::class);
2021-09-20 16:19:42 +02:00
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;
}
});
2020-07-23 10:29:36 +02:00
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'));
}
}