\View::share('article', $article);
\View::share('title', $article->title);
+ \View::share('meta', $article->getMetaData());
return view('social-articles.show');
}
--- /dev/null
+<?php
+
+
+namespace App\Models;
+
+
+trait HasMetaTags
+{
+ public function getMetaData(): array
+ {
+ return [
+ 'title' => $this->getMetaTitle(),
+ 'description' => $this->getMetaDescription(),
+ 'image' => $this->getMetaImage(),
+ 'url' => $this->getMetaUrl(),
+ ];
+
+ }
+
+ protected function getMetaTitle(): string
+ {
+ return $this->title;
+ }
+
+ protected function getMetaDescription(): string
+ {
+ return strip_tags($this->chapo);
+ }
+
+ protected function getMetaImage(): string
+ {
+ return $this->image('social_preview');
+ }
+
+ protected function getMetaUrl(): ?string
+ {
+ return request()->url();
+ }
+}
+
+
+
{
return route('actus-labos.show', ['slug' => $this->slug]);
}
+
+
}
*/
class SocialArticle extends Model implements PillBoxContract
{
- use HasSlug, HasMedias, HasSubscriberOnlyContent;
+ use HasSlug, HasMedias, HasSubscriberOnlyContent, HasMetaTags;
protected $fillable = [
'published',
'subscriber_only' => 'bool'
];
+ public $mediasParams = [
+ 'social_preview' => [
+ 'default' => [
+ [
+ 'name' => 'default',
+ 'ratio' => 1,
+ ],
+ ],
+ ],
+ ];
+
/**
* Increments view count
]
])
@section('contentFields')
+ @formField('medias', [
+ 'name' => 'social_preview',
+ 'label' => 'Image de prévisualisation',
+ 'max' => 1,
+ ])
+
@formField('wysiwyg', [
'name' => 'chapo',
'label' => 'Chapô',
<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
+
+
+
+ @if(isset($meta))
+ <meta property="og:title" content="{{Arr::get($meta, 'title', 'Prescription Santé - Le Quotidien')}}">
+ <meta property="og:description" content="{{Arr::get($meta, 'description', "L'ACTUALITÉ À LA UNE DE NOTRE QUOTIDIEN")}}">
+ <meta property="og:image" content="{{Arr::get($meta, 'image')}}">
+ <meta property="og:url" content="{{Arr::get($meta, 'url')}}">
+ <meta name="twitter:card" content="summary">
+ <meta property="og:type" content="article" />
+ <meta property="og:locale" content="fr_FR" />
+
+ @endif
+
+
</head>
<body>
<div id="app">