Files
qztool/backend/app/Models/Tool.php
T
DevandCursor 60daff2365 搭建轻舟一期门户、后台和统一登录。
让分类、会员和示例工具共用同一账号,本地即可跑通登录与授权。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-09 16:46:35 +08:00

48 lines
1.2 KiB
PHP

<?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);
}
}