diff --git a/app/Models/News.php b/app/Models/News.php index 2e454fd..7a51e3a 100644 --- a/app/Models/News.php +++ b/app/Models/News.php @@ -9,6 +9,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 SEO title. @@ -31,10 +34,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. @@ -198,4 +202,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.' . 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/Product.php b/app/Models/Product.php index b02fd74..7148469 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -9,6 +9,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; /** * @phpcs:disable Generic.Files.LineLength.TooLong @@ -41,10 +44,11 @@ use Illuminate\Support\Str; * @property-read \App\Models\Range $range Range Belongs to relationship. * @phpcs:enable */ -class Product extends Model +class Product extends Model implements SeoInterface { use ActivityLog; use HasFactory; + use SeoTrait; /** * The attributes that are mass assignable. @@ -189,4 +193,22 @@ class Product extends Model { return $this->belongsToMany(Commitment::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/Range.php b/app/Models/Range.php index c7f2a3c..08564cb 100644 --- a/app/Models/Range.php +++ b/app/Models/Range.php @@ -9,6 +9,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; // phpcs:disable Generic.Files.LineLength.TooLong /** @@ -36,10 +39,11 @@ use Illuminate\Support\Str; * @property-read \App\Models\Products $products Products Has Many relationship. */ // phpcs:enable -class Range extends Model +class Range extends Model implements SeoInterface { use ActivityLog; use HasFactory; + use SeoTrait; /** * The attributes that are mass assignable. @@ -170,4 +174,22 @@ class Range extends Model { return $this->hasMany(Product::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 4751c94..f764527 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. @@ -83,4 +87,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('models.classes.' . Str::singular($this->getTable())), + $this->seo_title, + $this->seo_description, + true, + \route(\config('seo.bo_route_prefix') . $this->getTable() . '.edit', $this), + '' + ); + } } diff --git a/app/Providers/ViewServiceProvider.php b/app/Providers/ViewServiceProvider.php index 3d888c2..31bb544 100644 --- a/app/Providers/ViewServiceProvider.php +++ b/app/Providers/ViewServiceProvider.php @@ -30,8 +30,11 @@ class ViewServiceProvider extends ServiceProvider if (!app()->runningInConsole()) { // * 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(); @@ -40,9 +43,9 @@ class ViewServiceProvider extends ServiceProvider // Get all the stamps that are pubished. $stamps = Cache::remember('randomStampsFooter', 360, function () { return DB::table('stamps') - ->select('picture', 'picture_alt', 'picture_title') - ->where('published', true) - ->get(); + ->select('picture', 'picture_alt', 'picture_title') + ->where('published', true) + ->get(); }); /** * Share a collection of 1 or 2 random stamps for footer. @@ -54,6 +57,6 @@ class ViewServiceProvider extends ServiceProvider 'randomStampsFooter', $stamps->isNotEmpty() ? $stamps->random($stamps->count() >= 2 ? 2 : 1) : [] ); - }//end if + } //end if } } diff --git a/composer.json b/composer.json index 6ec84f5..70e0439 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,8 @@ "ldc/web-admin-secure-laravel": "^2.0", "mews/purifier": "^3.4", "sentry/sentry-laravel": "*", - "uwil/k8s-laravel": "^1.2" + "uwil/k8s-laravel": "^1.2", + "uwil/seo-laravel": "^2.0" }, "require-dev": { "fakerphp/faker": "^1.9.1", diff --git a/composer.lock b/composer.lock index 4e71531..b38e56f 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": "5178515c35084bff77cb4cebec5574ab", + "content-hash": "9e1490aea9d5c6f581ccaaafbba3e052", "packages": [ { "name": "brick/math", @@ -8512,6 +8512,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 b3bb51d..604c2c4 100644 --- a/resources/lang/fr/models.php +++ b/resources/lang/fr/models.php @@ -16,5 +16,6 @@ return [ 'convictionpage' => 'page conviction', 'joinuspage' => 'page rejoignez-nous', 'testimonial' => 'témoignage', + 'seo' => 'contenu SEO|contenus SEO' ] ]; diff --git a/resources/lang/fr/validation.php b/resources/lang/fr/validation.php index bc9cd54..fc76ac9 100644 --- a/resources/lang/fr/validation.php +++ b/resources/lang/fr/validation.php @@ -270,7 +270,7 @@ return [ 'product_name' => 'nom du produit', 'publication' => 'publication', 'publish_at' => 'date de publication', - 'publish_at' => 'date de publication', + 'published' => 'état de publication', 'send_data' => 'autorisation d\'enregistrer des données', 'seo_description' => 'description SEO', 'seo_title' => 'titre SEO', @@ -284,6 +284,7 @@ return [ 'title_part1' => 'première partie du titre', 'title_part2' => 'seconde partie du titre', 'title_part3' => 'dernière partie du titre', + 'type' => 'type', 'unpublish_at' => 'date de fin de publication', 'unpublish_at' => 'date de fin de publication', 'video_id' => 'ID de la vidéo', diff --git a/resources/views/bo/layouts/nav-list.blade.php b/resources/views/bo/layouts/nav-list.blade.php index 0246864..63eb684 100644 --- a/resources/views/bo/layouts/nav-list.blade.php +++ b/resources/views/bo/layouts/nav-list.blade.php @@ -6,9 +6,16 @@ {{ __('Accueil') }} +
| {{ str(__('validation.custom.type'))->ucfirst() }} | +{{ str(__('validation.custom.seo_title'))->ucfirst() }} | +{{ str(__('validation.custom.seo_description'))->ucfirst() }} | +{{ str(__('validation.custom.published'))->ucfirst() }} | ++ |
|---|---|---|---|---|
| {{ str(trans_choice($seoItem->type, 1))->ucfirst() }} | +{{ $seoItem->seo_title }} | +{{ $seoItem->seo_description }} | ++ @if ($seoItem->status) + + @else + + @endif + | ++ + | +
| {{ __('crud.other.no_model_found', ['model' => __('models.classes.range')]) }} | +