OwnerPriceDirectLogistic.php 870 B

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