12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace App\Models\Goods;
- use App\Base\BaseModel;
- use Faker\Provider\Image;
- use Illuminate\Database\Eloquent\SoftDeletes;
- class Category extends BaseModel
- {
- use SoftDeletes;
- protected $table = "category";
- protected $fillable = ["name", "thumb", "level", "parent_id", "weight", "index_weight", "category_weight", "search_weight"];
- public function format(...$options)
- {
- $return = [
- "id" => $this->id,
- "name" => $this->name,
- "en_name" => $this->en_name,
- "thumb" => $this->thumb,
- "level" => $this->level,
- "parent_id" => optional($this->parent)->id ?? 0,
- "parent_name" => optional($this->parent)->name ?? 0,
- "weight" => $this->weight,
- "index_weight" => $this->index_weight,
- "category_weight" => $this->category_weight,
- "search_weight" => $this->search_weight,
- ];
- return $return;
- }
- public function parent()
- {
- return $this->belongsTo(Category::class, "parent_id");
- }
- public function childS()
- {
- return $this->hasMany(Category::class, "parent_id", "id");
- }
- public function gcMap()
- {
- return $this->hasMany(GoodsCategoryMap::class, "category_id", "id");
- }
- }
|