for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Giuga\LaravelSeoMetaBox\Traits;
use Giuga\LaravelSeoMetaBox\Models\Seo;
use Illuminate\Database\Eloquent\Model;
trait HasSeo
{
abstract public function getSeoOptions(): SeoOptions;
protected static function bootHasSeo()
static::saved(function (Model $model) {
$options = $model->getSeoOptions();
$seo = Seo::firstOrNew([
'type' => get_class($model),
'object_id' => $model->{$model->primaryKey},
]);
$seo->slug = $options->routePrefix ?? '';
if ($options->hasSlug) {
$seo->slug .= $model->{$options->slugField};
} else {
$seo->slug .= $model->{$model->primaryKey};
}
if (($title = request()->get('seo_title', false)) !== false) {
$seo->title = $title;
if ((empty($seo->title) || $options->overwriteOnUpdate) && isset($options->titleField)) {
$seo->title = $model->{$options->titleField};
if (($description = request()->get('seo_description', false)) !== false) {
$seo->description = $description;
if ((empty($seo->description) || $options->overwriteOnUpdate) && isset($options->descriptionField)) {
$seo->description = $model->{$options->descriptionField};
$seo->save();
});
static::retrieved(function (Model $model) {
app()->make('laravel-seo-meta-box')->addObjectOnPage(get_class($model), $model->{$model->primaryKey});
public function seo()
return $this->hasOne(Seo::class, 'object_id')->where('type', static::class);
hasOne()
If this is a false-positive, you can also ignore this issue in your code via the ignore-call annotation
ignore-call
return $this->/** @scrutinizer ignore-call */ hasOne(Seo::class, 'object_id')->where('type', static::class);