Files
qztool/backend/app/Models/Tool.php
T

48 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Tool extends Model
{
protected $fillable = [
'name', 'slug', 'icon', 'summary', 'content', 'type', 'open_url', 'language',
'internal_note', 'badge', 'required_entitlement', 'sort', 'is_recommended',
'status', 'published_at', 'clicks',
];
protected function casts(): array
{
return [
'is_recommended' => 'boolean',
'sort' => 'integer',
'clicks' => 'integer',
'published_at' => 'datetime',
];
}
public function scopePublished(Builder $query): Builder
{
return $query->where('status', 'published');
}
public function categories(): BelongsToMany
{
return $this->belongsToMany(Category::class, 'category_tool');
}
public function tags(): BelongsToMany
{
return $this->belongsToMany(Tag::class, 'tool_tag');
}
public function oauthClients(): HasMany
{
return $this->hasMany(OauthClient::class);
}
}