OwnerPriceDirectLogistic.php 992 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Support\Facades\DB;
  5. use App\Traits\ModelLogChanging;
  6. class OwnerPriceDirectLogistic extends Model
  7. {
  8. use ModelLogChanging;
  9. protected $fillable = [
  10. "name", //名称
  11. "base_km", //起步公里数
  12. "operation",//操作
  13. "target_id",//目标ID
  14. ];
  15. public function details()
  16. { //直发车计费对应车型费
  17. return $this->hasMany(OwnerPriceDirectLogisticCar::class,"owner_price_direct_logistic_id","id");
  18. }
  19. public function owners()
  20. { //货主中间表
  21. return $this->belongsToMany(Owner::class,"owner_price_direct_logistic_owner","owner_price_direct_logistic_id","owner_id");
  22. }
  23. public function getOwnerIdAttribute()
  24. { //获取货主ID数组
  25. return array_column(DB::select(DB::raw("SELECT * FROM owner_price_direct_logistic_owner WHERE owner_price_direct_logistic_id = ?"),[$this->id]),"owner_id");
  26. }
  27. }