فرعوني
جاري التحميل...

استخراج الوسوم من Model

استخراج الوسوم من Model

# التضمين

يجب عليك إضافة دالة toSEO لـ Model وتحديد الأعمدة التي تريدها.

1namespace App\Models;
2 
3use Illuminate\Database\Eloquent\Model;
4use Pharaonic\Laravel\SEO\Contracts\SEOContract;
5 
6class Article extends Model implements SEOContract
7{
8 /**
9 * The attributes that are mass assignable.
10 *
11 * @var array
12 */
13 protected $fillable = ['title', 'description', 'keywords'];
14 
15 /**
16 * Get SEO Data
17 *
18 * @return array
19 */
20 public function seo(): array
21 {
22 return [
23 'title' => $this->title,
24 'description' => $this->description,
25 'keywords' => $this->keywords,
26 'twitter' => [
27 'card' => 'app'
28 ]
29 ];
30 }
31}

# حقن بيانات الـ Model

فقط قوم بحقن SEO الخاص بالـ Model داخل مُجمِع الـ SEO لإستخدام هذه البيانات وعرضها في الصفحة فيما بعد.

1$article = Article::first();
2seo()->model($article);