123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace App\Models\Goods;
- use App\Base\BaseModel;
- use Illuminate\Database\Eloquent\SoftDeletes;
- use Illuminate\Support\Arr;
- class Spec extends BaseModel
- {
- use SoftDeletes;
- const FORMAT_ATTR = "attr";
- protected $table = "spec";
- public function attrs()
- {
- return $this->hasMany(SpecAttr::class, "spec_id", "id");
- }
- public function format(...$options)
- {
- $return = [
- "id" => $this->id,
- "name" => $this->name,
- "is_custom" => $this->is_custom,
- "index_weight" => $this->index_weight,
- "category_weight" => $this->category_weight,
- "search_weight" => $this->search_weight,
- ];
- if (in_array(self::FORMAT_ATTR, $options)) {
- $return['attr'] = $this->attrs->map(function (SpecAttr $m) {
- return [
- "id" => $m->id,
- "name" => $m->name,
- ];
- });
- }
- return $return;
- }
- }
|