海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.1 KiB

5 years ago
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. class AgentProduct extends BaseModel
  6. {
  7. use HasFactory, SoftDeletes;
  8. protected $guarded = ['id'];
  9. public function product()
  10. {
  11. return $this->belongsTo(Product::class);
  12. }
  13. public function coupon()
  14. {
  15. return $this->hasMany(Coupon::class);
  16. }
  17. public function fav()
  18. {
  19. return $this->hasOne(UserFav::class);
  20. }
  21. public function agent()
  22. {
  23. return $this->belongsTo(Agent::class);
  24. }
  25. public function category()
  26. {
  27. return $this->belongsTo(Category::class);
  28. }
  29. public function user()
  30. {
  31. return $this->hasOne(User::class, 'id', 'verifier');
  32. }
  33. public function item()
  34. {
  35. return $this->hasMany(AgentProductItem::class);
  36. }
  37. public function setChannelIdAttribute($value)
  38. {
  39. if (is_array($value)) {
  40. $this->attributes['channel_id'] = join(',', array_filter($value));
  41. }
  42. }
  43. public function setProductIdsAttribute($value)
  44. {
  45. if (is_array($value)) {
  46. $this->attributes['product_ids'] = join(',', array_filter($value));
  47. }
  48. }
  49. }