80 lines
1.8 KiB
PHP
80 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\EntityStatus;
|
|
use App\Enums\SourceLevel;
|
|
use App\Models\Concerns\HasPublicationScope;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
|
class Tool extends Model
|
|
{
|
|
use HasFactory;
|
|
use HasPublicationScope;
|
|
|
|
protected $fillable = [
|
|
'category_id',
|
|
'source_id',
|
|
'name',
|
|
'slug',
|
|
'summary',
|
|
'description',
|
|
'official_url',
|
|
'logo_url',
|
|
'pricing_type',
|
|
'platform',
|
|
'language',
|
|
'has_api',
|
|
'source_level',
|
|
'last_verified_at',
|
|
'status',
|
|
'is_stale',
|
|
'stale_note',
|
|
'alternative_tool_id',
|
|
'seo_title',
|
|
'seo_description',
|
|
'h1',
|
|
'canonical_url',
|
|
'published_at',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'has_api' => 'boolean',
|
|
'is_stale' => 'boolean',
|
|
'last_verified_at' => 'datetime',
|
|
'published_at' => 'datetime',
|
|
'source_level' => SourceLevel::class,
|
|
'status' => EntityStatus::class,
|
|
];
|
|
}
|
|
|
|
public function category(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Category::class);
|
|
}
|
|
|
|
public function source(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Source::class);
|
|
}
|
|
|
|
public function alternative(): BelongsTo
|
|
{
|
|
return $this->belongsTo(self::class, 'alternative_tool_id');
|
|
}
|
|
|
|
public function tags(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Tag::class, 'entity_tag_maps', 'entity_id', 'tag_id')
|
|
->wherePivot('entity_type', self::class)
|
|
->withTimestamps();
|
|
}
|
|
}
|