让分类、会员和示例工具共用同一账号,本地即可跑通登录与授权。 Co-authored-by: Cursor <cursoragent@cursor.com>
34 lines
872 B
PHP
34 lines
872 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class Category extends Model
|
|
{
|
|
protected $fillable = ['parent_id', 'name', 'slug', 'icon', 'sort', 'show_in_nav', 'status'];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return ['show_in_nav' => 'boolean', 'sort' => 'integer'];
|
|
}
|
|
|
|
public function parent(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Category::class, 'parent_id');
|
|
}
|
|
|
|
public function children(): HasMany
|
|
{
|
|
return $this->hasMany(Category::class, 'parent_id')->orderByDesc('sort')->orderBy('id');
|
|
}
|
|
|
|
public function tools(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Tool::class, 'category_tool');
|
|
}
|
|
}
|