Ich habe ein PHP-Laravel-Projekt, wo ich ein Feld zu einem/mehreren Modellen (Eloquent) hinzufügen muss. Ich habe nicht viel Erfahrung in PHP und habe Laravel nie zuvor versucht.Laravel Update Datenbanktabellen-Design
Die Klasse sieht wie folgt nun
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');
}
}
Ich möchte einen String-Feld hinzufügen „Ebene“ genannt, aber ich habe keine Ahnung, wie man das macht. Wenn ich zuerst das Feld in MySQL erstelle und die Modelle dann aktualisiert werden, wenn ich die Modelle aktualisiere und dann Laravel MySQL für mich aktualisiere?
Im freut sich auf zu hören, was ich tun kann :)
Verwenden Sie Migrationen? Wenn nicht, empfehle ich Ihnen dringend https://laravel.com/docs/5.2/migrations –
Ein nützlicher Link hier: http://stackoverflow.com/questions/16791613/add-new-column-migrate-to-database –
Ja, das Projekt verwendet Migrationen, aber ich habe das Projekt gerade erst von jemand anderem übernommen – Alpo