Pharaonic
Loading...

Load From Model

Load From Model

# Inclusion

You have to add toSEO method to your model and specify your columns.

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 Injection

Just inject the model SEO in the SEO collector to generate it on the page later.

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