初始化

This commit is contained in:
2026-08-08 18:27:38 +08:00
parent efc150c937
commit 060eb79c09
336 changed files with 24613 additions and 15 deletions
+37
View File
@@ -0,0 +1,37 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Category extends Model
{
protected $fillable = [
'name',
'slug',
'type',
'parent_id',
'sort',
];
protected $casts = [
'parent_id' => 'integer',
'sort' => 'integer',
];
public function products(): HasMany
{
return $this->hasMany(Product::class, 'category_id');
}
public function articles(): HasMany
{
return $this->hasMany(Article::class, 'category_id');
}
public function scopeOfType($query, string $type)
{
return $query->where('type', $type)->orderBy('sort')->orderBy('name');
}
}