OwnerPriceDirectLogistic.php 931 B

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