1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?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";
- public function format(...$options)
- {
- $return = [
- "id" => $this->id,
- "name" => $this->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");
- }
- }
|