1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace App\Models;
- use Dcat\Admin\Traits\HasDateTimeFormatter;
- use Dcat\Admin\Traits\ModelTree;
- use Illuminate\Database\Eloquent\Model;
- use Spatie\EloquentSortable\Sortable;
- use Spatie\EloquentSortable\SortableTrait;
- class BaseProduct extends Model implements Sortable
- {
- use HasDateTimeFormatter;
- use SortableTrait;
- protected $table = 'base_product';
- // 可选:你可以在这里自定义排序配置
- public $sortable = [
- 'order_column_name' => 'order', // 排序字段
- 'sort_when_creating' => false, // 创建时自动排序
- ];
- protected $casts = [
- 'created_at' => 'datetime:Y-m-d H:i:s',
- 'updated_at' => 'datetime:Y-m-d H:i:s',
- 'parameters' => 'json', // 将 attributes 字段转换为数组
- ];
- public function baseProductCategory()
- {
- return $this->hasOne(BaseProductCategory::class,'id','category_id');
- }
- // 一对多关联
- public function images()
- {
- return $this->hasMany(BaseProductImage::class, 'product_id');
- }
- }
|