2025-04-25 11:30:44 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\model;
|
|
|
|
|
|
|
|
|
|
use support\Model;
|
|
|
|
|
|
|
|
|
|
class Location extends Model
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* The table associated with the model.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $table = 'locations';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The primary key associated with the table.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $primaryKey = 'id';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Indicates if the model should be timestamped.
|
|
|
|
|
*
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
|
|
|
|
public $timestamps = false;
|
|
|
|
|
|
2025-05-13 15:29:56 +08:00
|
|
|
//批量赋值黑名单
|
|
|
|
|
protected $guarded = ['created_at', 'updated_at'];
|
|
|
|
|
|
2025-04-25 11:30:44 +08:00
|
|
|
/**
|
|
|
|
|
* Get the vehicles for the location.
|
|
|
|
|
*/
|
|
|
|
|
public function vehicles()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Vehicle::class, 'locations_id', 'id');
|
|
|
|
|
}
|
|
|
|
|
/**
|
2025-04-25 16:54:54 +08:00
|
|
|
* 目的地关联
|
2025-04-25 11:30:44 +08:00
|
|
|
* Get the vehicles for the location.
|
|
|
|
|
*/
|
|
|
|
|
public function finalVehicles()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Vehicle::class, 'final_locations_id', 'id');
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-25 16:54:54 +08:00
|
|
|
/**
|
|
|
|
|
* Get the FBO vehicles for the location.
|
|
|
|
|
*/
|
|
|
|
|
public function fboVehicles()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Vehicle::class, 'fbo_locations_id', 'id');
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-25 11:30:44 +08:00
|
|
|
/**
|
|
|
|
|
* Scope a query to only include locations that have vehicles.
|
|
|
|
|
*/
|
|
|
|
|
public function scopeHasVehicles($query)
|
|
|
|
|
{
|
|
|
|
|
return $query->whereHas('vehicles');
|
|
|
|
|
}
|
|
|
|
|
}
|