Wie fügen Sie neue Spalte in Laravel die Standard-Benutzer-Tabelle?

Modifizierte ich die Standard-laravel ist in der Tabelle user, und ich wusste, dass durch die Schaffung meiner eigenen migration.

Hier ist meine migration sample:

 public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->string('username', 15)->unique()->after('id');
            $table->string('lastname', 15)->unique()->after('username');
            $table->string('firstname', 15)->unique()->after('lastname');
            $table->string('contact')->nullable()->after('email');
            $table->date('birthday')->after('contact');
            $table->tinyInteger('status')->default(1)->after('birthday');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn('username');
            $table->dropColumn('lastname');
            $table->dropColumn('firstname');
            $table->dropColumn('contact');
            $table->dropColumn('birthday');
            $table->dropColumn('status');
        });
    }

Und ich entfernt die Spalte name im Standard laravel-Tabelle, so dass es wie folgt aussieht:

public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('email')->unique();
            $table->string('password', 60);
            $table->rememberToken();
            $table->timestamps();
        });
    }

Überprüfte ich die Werte aus meinem Formular in den AuthController und ich habe ein Problem beim abrufen der Werte. Hier ist, was ich Hinzugefügt im AuthController

protected $username = 'username'; //choose username instead of email
protected $redirectPath = '/dashboard'; //if successful login
protected $loginPath = 'auth/login'; //if not login
protected $redirectAfterLogout = 'auth/login'; //redirect after login

/**
 * Create a new authentication controller instance.
 *
 * @return void
 */
public function __construct()
{
    $this->middleware('guest', ['except' => 'getLogout']);
}

/**
 * Get a validator for an incoming registration request.
 *
 * @param  array  $data
 * @return \Illuminate\Contracts\Validation\Validator
 */
protected function validator(array $data)
{
    return Validator::make($data, [
        'username'  => 'required|min:8|max:16|unique:users',
        'lastname'  => 'required',
        'firstname' => 'required',
        'contact'   => 'required',
        'birthday'  => 'date_format: Y-m-d',
        'email'     => 'required|email|max:255|unique:users',
        'password'  => 'required|confirmed|min:6',
    ]);
}

/**
 * Create a new user instance after a valid registration.
 *
 * @param  array  $data
 * @return User
 */
protected function create(array $data)
{

    //dd($data); -- I can get all the values here

    //I added my own column in this part to save. Is it correct?
    return User::create([
        'username'  =>  $data['username'],
        'lastname'  =>  $data['lastname'],
        'firstname' =>  $data['firstname'],
        'birthday'  =>  $data['birthday'],
        'contact'   =>  $data['contact'],
        'email'     =>  $data['email'],
        'status'    =>  1,
        'password'  =>  bcrypt($data['password']),
    ]);
}

Wenn ich versuche, die Daten zu speichern kann ich nur speichern Sie diese Spalten

mysql> select * from users \G;
*************************** 1. row ***************************
            id: 1
      username:
      lastname:
     firstname:
         email: myemail@gmail.com
       contact: NULL
      birthday: 0000-00-00
        status: 1
      password: $2y$10$3NkmqZaje4MKzheqPZKbhOIGD7ZlqYRfIP6DJZz4zb4gXVNvFsv2W
remember_token: PCYczF2Y9ts97TvbDOLsiXO5hxkekkxysmMYuIdN5MsaIY8TnroEof6d2jVM
    created_at: 2015-09-17 06:56:43
    updated_at: 2015-09-17 07:00:35
1 row in set (0.00 sec)

ERROR:
No query specified

Wie kann ich meine neue Spalte in der Datenbank?

Ok, das ist alles, ich hoffe Ihr könnt mir helfen.

InformationsquelleAutor Jerielle | 2015-09-17
Schreibe einen Kommentar