BaseProduct.php 869 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace App\Models;
  3. use Dcat\Admin\Traits\HasDateTimeFormatter;
  4. use Illuminate\Database\Eloquent\Model;
  5. class BaseProduct extends Model
  6. {
  7. use HasDateTimeFormatter;
  8. protected $table = 'base_product';
  9. protected $fillable = ['id', 'title', 'keywords', 'description', 'sku', 'category_id', 'issuance_date', 'order', 'enabled', 'content', 'parameters', 'created_at', 'updated_at'];
  10. protected $casts = [
  11. 'created_at' => 'datetime:Y-m-d H:i:s',
  12. 'updated_at' => 'datetime:Y-m-d H:i:s',
  13. 'parameters' => 'json', // 将 attributes 字段转换为数组
  14. ];
  15. public function baseProductCategory()
  16. {
  17. return $this->hasOne(BaseProductCategory::class,'id','category_id');
  18. }
  19. // 一对多关联
  20. public function images()
  21. {
  22. return $this->hasMany(BaseProductImage::class, 'product_id');
  23. }
  24. }