Model定义:(类型转换)
protected $casts = [ 'age' => 'integer' ];
<?php namespace TrOrderModel; /** * 售后退款单模型 * * @author llh */ class AfterSaleModel extends Model { /** * 表名 * * @var string */ protected $table = 'after_sale'; /** * 字段转换 * * @var array */ protected $casts = [ 'images' => 'json' ]; /** * 关联退货物流表 * * @return IlluminateDatabaseEloquentRelationsHasOne */ public function delivery() { return $this->hasOne(AfterSaleDeliveryModel::class, 'after_sale_bn', 'bn'); } /** * 关联退款流水表 * * @return IlluminateDatabaseEloquentRelationsHasOne */ public function flow() { return $this->hasOne(RefundFlowModel::class, 'after_sale_bn', 'bn'); } /** * 关联自身 * * @return IlluminateDatabaseEloquentRelationsHasMany */ public function self() { return $this->hasMany(self::class, 'order_good_no', 'order_good_no'); } /** * 关联兄弟 * * @return IlluminateDatabaseEloquentRelationsHasMany */ public function siblings() { return $this->hasMany(self::class,'order_shop_no', 'order_shop_no'); } }