125 lines
2.6 KiB
PHP
125 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace app\console\model;
|
|
|
|
use support\Model;
|
|
|
|
/**
|
|
* VehicleNewModel
|
|
*/
|
|
class VehicleNewModel extends Model
|
|
{
|
|
/**
|
|
* The connection name for the model.
|
|
*
|
|
* @var string|null
|
|
*/
|
|
protected $connection = 'mysql';
|
|
|
|
/**
|
|
* The table associated with the model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $table = 'hs_vehicle_new';
|
|
|
|
/**
|
|
* The primary key associated with the table.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $primaryKey = 'id';
|
|
|
|
/**
|
|
* Indicates if the model should be timestamped.
|
|
*
|
|
* @var bool
|
|
*/
|
|
public $timestamps = true;
|
|
|
|
/**
|
|
* 模型的数据字段的保存格式。
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $dateFormat = 'U';
|
|
|
|
/**x`
|
|
* 允许自动填充模型字段
|
|
*/
|
|
protected $fillable = ['id', 'vin', 'brand', 'cover', 'album', 'price', 'type', 'energy', 'model', 'video', 'views', 'creater', 'created_at', 'updated_at', 'location'];
|
|
|
|
/**
|
|
* 不允许自动填充模型字段
|
|
*/
|
|
protected $guarded = [];
|
|
|
|
const TRANS_FIELDS = [
|
|
'name', 'condition_desc'
|
|
];
|
|
|
|
/**
|
|
* 单条翻译
|
|
*/
|
|
public function translation()
|
|
{
|
|
return $this->hasOne(VehicleNewTranslationModel::class, 'vehicle_id')->where('locale', locale());
|
|
}
|
|
|
|
/**
|
|
* 多条翻译
|
|
*/
|
|
public function translations()
|
|
{
|
|
return $this->hasMany(VehicleNewTranslationModel::class, 'vehicle_id');
|
|
}
|
|
|
|
public function brand()
|
|
{
|
|
return $this->belongsTo(BrandModel::class, 'brand');
|
|
}
|
|
|
|
public function models()
|
|
{
|
|
return $this->belongsTo(ModelModel::class, 'model');
|
|
}
|
|
|
|
public function location()
|
|
{
|
|
return $this->belongsTo(LocationModel::class, 'location');
|
|
}
|
|
|
|
public function types()
|
|
{
|
|
return $this->belongsTo(TypesModel::class, 'type', 'id');
|
|
}
|
|
|
|
public function energy()
|
|
{
|
|
return $this->belongsTo(EnergyModel::class, 'energy', 'id');
|
|
}
|
|
|
|
public function album()
|
|
{
|
|
return $this->hasMany(VehicleNewAlbumModel::class, 'vehicle_id', 'id');
|
|
}
|
|
|
|
public function asked()
|
|
{
|
|
return $this->hasMany(VehicleNewAskedModel::class, 'vehicle_id', 'id');
|
|
}
|
|
|
|
public function trait()
|
|
{
|
|
return $this->hasMany(VehicleNewTraitModel::class, 'vehicle_id', 'id');
|
|
}
|
|
|
|
public function content()
|
|
{
|
|
return $this->hasMany(VehicleNewContentModel::class, 'vehicle_id', 'id');
|
|
}
|
|
public function creater()
|
|
{
|
|
return $this->belongsTo(AdminsModel::class, 'creater','id');
|
|
}
|
|
} |