public function up()
{
Schema::table('users', function($table)
{
$table->string('firstname', 30);
$table->string('lastname', 30);
$table->string('username', 30)->unique();
$table->string('profilepicture', 200);
$table->integer('role_id')->unsigned();
$table->foreign('role_id')->references('id')->on('roles');
});
}
public function down()
{
Schema::table('users', function($table)
{
$table->dropForeign('role_id');
$table->dropColumn('firstname', 'lastname', 'username', 'role_id', 'profilepicture');
});
}
I wouldn't mind ditching the username entirely and using the email as unique identifier, then showing the first_name
and last_name
or name
(which could be used solely for display purposes as a substitute for username).
Wonder what the best way would be to handle already existing first_name and last_name fields in existing Laravel projects? You'd almost have to write a migration script that checks database fields to see what is already set up, but that gets dangerous real quick. In general, the first thing I do is remove name
and add first_name
and last_name
fields as soon as I start a project, so all my existing projects are already set up with first and last names in this one form or another.