让分类、会员和示例工具共用同一账号,本地即可跑通登录与授权。 Co-authored-by: Cursor <cursoragent@cursor.com>
48 lines
1.2 KiB
PHP
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);
|
|
}
|
|
}
|