我有一个php laravel项目,我需要添加一个字段到一个/多个模型(雄辩)。我没有太多的PHP经验,从来没有尝试过laravel。Laravel更新数据库表设计
这个类是现在这个样子
class Player extends Eloquent
{
use GenderTrait;
use VisibilityTrait;
use PlayerPhotoTrait;
use PlayerActionTrait;
const GENDER_MALE = 2;
const GENDER_FEMALE = 1;
/**
* The database table used by model.
*
* @var string
*/
protected $table = 'players';
/**
* Parameters for `actions` relation.
*
* @see PlayerActionTrait::actions()
* @var array
*/
protected $actionModel = [
'name' => 'PlayerAction',
'foreignKey' => 'player_id',
];
/**
* The list of mass-assignable attributes.
*
* @var array
*/
protected $fillable = [
'name',
'start_value',
'gender',
'is_visible',
'nation',
];
/**
* The list of validation rules.
*
* @var array
*/
public static $rules = [
'name' => 'required',
'nation' => 'required|numeric',
'start_value' => 'required|numeric',
];
/**
* @inheritdoc
*/
protected static function boot()
{
parent::boot();
}
/**
* Players country.
*
* @return Country
*/
public function country()
{
return $this->belongsTo('Country', 'nation');
}
/**
* Player videos.
*
* @return mixed
*/
public function videos()
{
return $this->morphMany('YoutubeLink', 'owner');
}
}
我想添加一个名为“水平”的字符串场,但我不知道如何去做。如果我先在MySQL中创建字段,然后模型得到更新,如果我更新模型,然后Laravel为我更新MySQL?
进出口期待听到我能做些什么:)
您使用的是迁移吗?如果不是,我强烈建议你这样做https://laravel.com/docs/5.2/migrations –
这里有用的链接:http://stackoverflow.com/questions/16791613/add-new-column-migrate-to-database –
是的,该项目正在使用迁移,但我只是刚刚从别人那里接管了该项目 – Alpo