Cart.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Models;
  3. use App\Base\BaseModel;
  4. use App\Models\Goods\Goods;
  5. use Illuminate\Support\Arr;
  6. /**
  7. * App\Models\Cart
  8. *
  9. * @property int $id
  10. * @property int $user_id
  11. * @property int $goods_id
  12. * @property array $extra
  13. * @property int $count
  14. * @property \Illuminate\Support\Carbon|null $created_at
  15. * @property \Illuminate\Support\Carbon|null $updated_at
  16. * @method static \Illuminate\Database\Eloquent\Builder|Cart newModelQuery()
  17. * @method static \Illuminate\Database\Eloquent\Builder|Cart newQuery()
  18. * @method static \Illuminate\Database\Eloquent\Builder|Cart query()
  19. * @method static \Illuminate\Database\Eloquent\Builder|Cart whereCount($value)
  20. * @method static \Illuminate\Database\Eloquent\Builder|Cart whereCreatedAt($value)
  21. * @method static \Illuminate\Database\Eloquent\Builder|Cart whereExtra($value)
  22. * @method static \Illuminate\Database\Eloquent\Builder|Cart whereGoodsId($value)
  23. * @method static \Illuminate\Database\Eloquent\Builder|Cart whereId($value)
  24. * @method static \Illuminate\Database\Eloquent\Builder|Cart whereUpdatedAt($value)
  25. * @method static \Illuminate\Database\Eloquent\Builder|Cart whereUserId($value)
  26. * @mixin \Eloquent
  27. * @property-read mixed $thumb
  28. * @property-read mixed $goods_name
  29. * @property-read mixed $sn
  30. * @property-read mixed $custom
  31. * @property-read mixed $sku_id
  32. * @property-read Goods|null $goods
  33. */
  34. class Cart extends BaseModel
  35. {
  36. protected $table = "cart";
  37. protected $casts = [
  38. "extra" => "array",
  39. ];
  40. public function getThumbAttribute()
  41. {
  42. return Arr::get($this->extra, "thumb", "");
  43. }
  44. public function getSnAttribute()
  45. {
  46. return Arr::get($this->extra, "sn", "");
  47. }
  48. public function getSkuIdAttribute()
  49. {
  50. return Arr::get($this->extra, "sku_id", "");
  51. }
  52. public function getGoodsNameAttribute()
  53. {
  54. return Arr::get($this->extra, "goods_name", "");
  55. }
  56. public function getCustomAttribute()
  57. {
  58. return Arr::get($this->extra, "custom", []);
  59. }
  60. public function goods()
  61. {
  62. return $this->belongsTo(Goods::class);
  63. }
  64. }