finale 2.0.0.0
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||
|
||||
class Tag extends Model
|
||||
{
|
||||
protected $table = 'tags';
|
||||
|
||||
protected $fillable = ['name', 'slug', 'color', 'order_column'];
|
||||
|
||||
protected $casts = [
|
||||
'order_column' => 'integer',
|
||||
];
|
||||
|
||||
protected static function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function (self $tag) {
|
||||
if (empty($tag->slug)) {
|
||||
$tag->slug = str()->slug($tag->name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function individui(): MorphToMany
|
||||
{
|
||||
return $this->morphedByMany(Individuo::class, 'taggable');
|
||||
}
|
||||
|
||||
public function gruppi(): MorphToMany
|
||||
{
|
||||
return $this->morphedByMany(Gruppo::class, 'taggable');
|
||||
}
|
||||
|
||||
public function eventi(): MorphToMany
|
||||
{
|
||||
return $this->morphedByMany(Evento::class, 'taggable');
|
||||
}
|
||||
|
||||
public function documenti(): MorphToMany
|
||||
{
|
||||
return $this->morphedByMany(Documento::class, 'taggable');
|
||||
}
|
||||
|
||||
public function mailingLists(): MorphToMany
|
||||
{
|
||||
return $this->morphedByMany(MailingList::class, 'taggable');
|
||||
}
|
||||
|
||||
public function getCountAttribute(): int
|
||||
{
|
||||
return $this->individui()->count()
|
||||
+ $this->gruppi()->count()
|
||||
+ $this->eventi()->count()
|
||||
+ $this->documenti()->count()
|
||||
+ $this->mailingLists()->count();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user