Laravel 5.1 Authentication registration not getting data
I have been searching for this and I cannot find an answer. The Laravel docs are a little vague.
I am trying to register a user and for the most part it is working using Laravel's built in authentication tools. All I am trying to do is, instead of just have a name field when a user registers, I want to have a first_name and last_name field.
In order to do this I have created a migration that extends the users table that the defualt laravel migration creates. Here is the code for that:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddFirstNameLastNameToUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
Schema::table('users', function($table) {
$table->dropColumn('name');
$table->string('first_name')->after('id');
$table->string('last_name')->after('first_name');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
Schema::table('users', function($table) {
$table->dropColumn('last_name');
$table->dropColumn('first_name');
$table->string('name');
});
}
}
So after that, I created the view for the registration form. Here is the code for that:
@extends('../master')
@section('content')
<div class="container">
<div class="row">
{!! Form::open(['url' => url('auth/register'), 'method' => 'post']) !!}
<div class="form-group">
{!! Form::label('email', 'Email') !!}
{!! Form::email('email', null, ['class'=>'form-control', 'id'=>'username']) !!}
</div>
<div class="form-group">
{!! Form::label('first_name', 'First Name') !!}
{!! Form::text('first_name', null, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('last_name', 'Last Name') !!}
{!! Form::text('last_name', null, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('password', 'Password') !!}
{!! Form::password('password', ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('password_confirmation', 'Password Confirmation') !!}
{!! Form::password('password_confirmation', ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit("Register") !!}
</div>
{!! Form::close() !!}
</div>
</div>
@stop
It the says the validate function in the auth controller will validate the input, so here is the code for that:
protected function validator(array $data)
{
return Validator::make($data, [
'first_name' => 'required|max:255',
'last_name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
]);
}
Now all this seems to work fine the problem is in the create function in the auth controller. The auth method takes in an array of data, The laravel 5.1 docs dont say what is going to be in this array. I assumed it would be the form fields that were in the registration form but I am not getting the first_name and last_name field that are in registaction form. It must be validating correctly cause entries are getting saved in the DB but the first_name and last_name columns are not getting saved. I did a dd on the data array but its not dying so I don't know what is in the array and how to get information in that array.
Side note, the laravel docs also dont say where errors will be saved when a registration validation fails so I dont know how to display registration errors.
edit:
Here is the model, the first_name and last_name fields weren't fillable. I then made them fillable at the suggestion of @Andrew, it is still not filling the fields.
<?php
namespace SellIt;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['first_name', 'last_name', 'email', 'password'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = ['password', 'remember_token'];
}
Answer
So... funny story. It was showing a row in MySQL workbench so I would right click on the row, hit delete and it would show the table as empty. Turns out MySQL Workbench was not actually deleting the record. I manually deleted the record with a query and registered again and it worked. Thanks for your help guys.
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?