Conditions | 8 |
Paths | 1 |
Total Lines | 25 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | protected static function bootHasSeo() |
||
13 | { |
||
14 | static::saved(function (Model $model) { |
||
15 | $options = $model->getSeoOptions(); |
||
16 | $seo = Seo::firstOrNew([ |
||
17 | 'type' => get_class($model), |
||
18 | 'object_id' => $model->{$model->primaryKey}, |
||
19 | ]); |
||
20 | $seo->slug = $options->routePrefix ?? ''; |
||
21 | if ($options->hasSlug) { |
||
22 | $seo->slug .= $model->{$options->slugField}; |
||
23 | } else { |
||
24 | $seo->slug .= $model->{$model->primaryKey}; |
||
25 | } |
||
26 | if ((empty($seo->title) || $options->overwriteOnUpdate) && isset($options->titleField)) { |
||
27 | $seo->title = $model->{$options->titleField}; |
||
28 | } |
||
29 | if ((empty($seo->description) || $options->overwriteOnUpdate) && isset($options->descriptionField)) { |
||
30 | $seo->description = $model->{$options->descriptionField}; |
||
31 | } |
||
32 | $seo->save(); |
||
33 | }); |
||
34 | |||
35 | static::retrieved(function (Model $model) { |
||
36 | app()->make('laravel-seo-meta-box')->addObjectOnPage(get_class($model), $model->{$model->primaryKey}); |
||
37 | }); |
||
45 |