diff --git a/app/Models/News.php b/app/Models/News.php index 86cfa32..b0a1553 100644 --- a/app/Models/News.php +++ b/app/Models/News.php @@ -8,6 +8,9 @@ use App\Traits\Models\ActivityLog; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Str; +use Uwil\Seo\Laravel\Interfaces\SeoInterface; +use Uwil\Seo\Laravel\Objects\SeoItem; +use Uwil\Seo\Laravel\Traits\SeoTrait; /** * @property string $seo_title Utilisé pour la balise title de la page. @@ -25,10 +28,11 @@ use Illuminate\Support\Str; * @property-read \Carbon\Carbon $created_at Created date. * @property-read \Carbon\Carbon $updated_at Updated date. */ -class News extends Model +class News extends Model implements SeoInterface { use ActivityLog; use HasFactory; + use SeoTrait; /** * The attributes that are mass assignable. @@ -163,4 +167,22 @@ class News extends Model } return false; } + + // * SEO TRAIT OVERLOAD + /** + * Transform to seoModel + * + * @return \App\Objects\SeoItem + */ + public function toSeoItem(): SeoItem + { + return new SeoItem( + \trans('models.classes.' . $this->getTable()), + $this->seo_title, + $this->seo_description, + $this->published ?? false, + \route(\config('seo.bo_route_prefix') . $this->getTable() . '.edit', $this), + $this->published ? \route('fo.' . Str::singular($this->getTable()) . '.show', $this) : '' + ); + } } diff --git a/app/Models/Product.php b/app/Models/Product.php index c9dbb3a..6d13548 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -8,6 +8,9 @@ use App\Traits\Models\ActivityLog; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Str; +use Uwil\Seo\Laravel\Interfaces\SeoInterface; +use Uwil\Seo\Laravel\Objects\SeoItem; +use Uwil\Seo\Laravel\Traits\SeoTrait; /** * @property string $seo_title Utilisé pour la balise title de la page. @@ -36,10 +39,11 @@ use Illuminate\Support\Str; * @property-read \App\Models\Picto $pictos Pictos Many-to-many relationship. * @property-read \App\Models\Range $range Range Belongs to relationship. */ -class Product extends Model +class Product extends Model implements SeoInterface { use ActivityLog; use HasFactory; + use SeoTrait; /** * The attributes that are mass assignable. @@ -168,4 +172,22 @@ class Product extends Model { return $this->belongsToMany(Picto::class); } + + // * SEO TRAIT OVERLOAD + /** + * Transform to seoModel + * + * @return \App\Objects\SeoItem + */ + public function toSeoItem(): SeoItem + { + return new SeoItem( + \trans('models.classes.' . Str::singular($this->getTable())), + $this->seo_title, + $this->seo_description, + $this->published ?? false, + \route(\config('seo.bo_route_prefix') . $this->getTable() . '.edit', $this), + $this->published ? \route('fo.' . $this->getTable() . '.show', $this) : '' + ); + } } diff --git a/app/Models/StaticPage.php b/app/Models/StaticPage.php index 413f6f2..f6623bd 100644 --- a/app/Models/StaticPage.php +++ b/app/Models/StaticPage.php @@ -8,6 +8,9 @@ use App\Traits\Models\ActivityLog; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Str; +use Uwil\Seo\Laravel\Interfaces\SeoInterface; +use Uwil\Seo\Laravel\Objects\SeoItem; +use Uwil\Seo\Laravel\Traits\SeoTrait; /** * @property \App\Enums\StaticPageType $type Page type (StaticPageEnum). @@ -19,10 +22,11 @@ use Illuminate\Support\Str; * @property-read \Illuminate\Support\Carbon $created_at Created date. * @property-read \Illuminate\Support\Carbon $updated_at Updated date. */ -class StaticPage extends Model +class StaticPage extends Model implements SeoInterface { use ActivityLog; use HasFactory; + use SeoTrait; /** * The attributes that are mass assignable. @@ -109,4 +113,22 @@ class StaticPage extends Model ToolboxHelper::assertFieldIsUnique($table, 'title', $title, $id); ToolboxHelper::assertFieldIsUnique($table, 'slug', Str::slug($title), $id); } + + // * SEO TRAIT OVERLOAD + /** + * Transform to seoModel + * + * @return \App\Objects\SeoItem + */ + public function toSeoItem(): SeoItem + { + return new SeoItem( + \trans_choice('models.classes.' . Str::singular($this->getTable()), 1), + $this->seo_title, + $this->seo_description, + false, + \route(\config('seo.bo_route_prefix') . $this->getTable() . '.edit', $this), + '' + ); + } } diff --git a/app/Providers/ViewServiceProvider.php b/app/Providers/ViewServiceProvider.php index b068b11..4b90638 100644 --- a/app/Providers/ViewServiceProvider.php +++ b/app/Providers/ViewServiceProvider.php @@ -50,7 +50,11 @@ class ViewServiceProvider extends ServiceProvider // * FORCE BOOTSTRAP PAGINATOR (or custom if in front) // Early boot, request wont be filled as expected. - if (collect(explode('/', \request()->getPathInfo()))->get(1) === 'bo') { + // For the moment, we exclude the seo page because the new pagination system doesn't work in the package. + if ( + collect(explode('/', \request()->getPathInfo()))->get(1) === 'bo' && + collect(explode('/', \request()->getPathInfo()))->last() !== 'seo' + ) { Paginator::defaultView('bo.modules.pagination'); } else { Paginator::useBootstrapFive(); diff --git a/composer.json b/composer.json index be6d903..8d511eb 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,8 @@ "mews/purifier": "^3.4", "propaganistas/laravel-phone": "^5.0", "sentry/sentry-laravel": "*", - "uwil/k8s-laravel": "*" + "uwil/k8s-laravel": "*", + "uwil/seo-laravel": "^2.0" }, "require-dev": { "fakerphp/faker": "^1.9.1", diff --git a/composer.lock b/composer.lock index 3cc5649..8fe1616 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b72fd73d510285ac10b0b17fe78928c9", + "content-hash": "2231f3e8a4eba50d8cab64366c6dcfb1", "packages": [ { "name": "axlon/laravel-postal-code-validation", @@ -8811,6 +8811,53 @@ ], "description": "Laravel requirements for k8s" }, + { + "name": "uwil/seo-laravel", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://lab.s-web.fr/ldc-web/projets/seo-laravel.git", + "reference": "518918847ada3a75dceda343ca074d7cdf8d0458" + }, + "dist": { + "type": "zip", + "url": "https://lab.s-web.fr/api/v4/projects/96/packages/composer/archives/uwil/seo-laravel.zip?sha=518918847ada3a75dceda343ca074d7cdf8d0458", + "reference": "518918847ada3a75dceda343ca074d7cdf8d0458", + "shasum": "" + }, + "require": { + "illuminate/support": "~8|~9|~10", + "laravel/framework": "~8|~9|~10", + "php": "~7.4|~8" + }, + "require-dev": { + "slevomat/coding-standard": "^8.3", + "squizlabs/php_codesniffer": "^3.7" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Uwil\\Seo\\Laravel\\SeoServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Uwil\\Seo\\Laravel\\": "src/" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Demangeat", + "email": "nicolas.demangeat@ldc.fr" + } + ], + "description": "Find Seo title and seo description of a model" + }, { "name": "vlucas/phpdotenv", "version": "v5.5.0", diff --git a/config/seo.php b/config/seo.php new file mode 100644 index 0000000..33691da --- /dev/null +++ b/config/seo.php @@ -0,0 +1,12 @@ + 'bo.', + 'blade' => 'bo.pages.seo.index', + 'middlewares' => [ + 'web', + 'admin-secure', + 'auth:backend' + ], + 'guard' => 'backend' +]; diff --git a/resources/lang/fr/models.php b/resources/lang/fr/models.php index a4d64f6..5071dbc 100644 --- a/resources/lang/fr/models.php +++ b/resources/lang/fr/models.php @@ -14,5 +14,6 @@ return [ 'game' => 'jeu|jeux', 'klub_bloc' => 'bloc klub', 'historicalMilestone' => 'jalon historique', + 'seo' => 'contenu SEO|contenus SEO' ] ]; diff --git a/resources/lang/fr/validation.php b/resources/lang/fr/validation.php index a79fe21..3683271 100644 --- a/resources/lang/fr/validation.php +++ b/resources/lang/fr/validation.php @@ -285,6 +285,7 @@ return [ 'third_image' => 'troisième image', 'title_line1' => 'première ligne du titre', 'title_line2' => 'deuxième ligne du titre', + 'type' => 'type', 'unpublish_at' => 'date de fin de publication', 'url' => 'url', ], diff --git a/resources/views/bo/layouts/nav-list.blade.php b/resources/views/bo/layouts/nav-list.blade.php index 099328b..3a5afce 100644 --- a/resources/views/bo/layouts/nav-list.blade.php +++ b/resources/views/bo/layouts/nav-list.blade.php @@ -6,6 +6,12 @@ {{ __('Accueil') }} +