Good afternoon,
I want to add the type field to the user of a laravel system and I'm doing it as follows:
migration
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->smallInteger('type');
$table->rememberToken();
$table->timestamps();
});
}
register.blade.php (I've added a select to type):
<div class="form-group">
<label for="type" class="col-md-4 control-label">Tipo de usuário: </label>
<div class="col-md-6">
<select class="form-control" name="type" style="width:350px">
<option value="1">Cliente</option>
<option value="2">Funcionário</option>
<option value="3">Gerente</option>
</select>
</div>
RegisterController:
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'type' => 'required',
'password' => 'required|min:6|confirmed',
]);
}
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'type' => $data['type'],
'password' => bcrypt($data['password']),
]);
}
The user is saved but always with type 0 and I do not understand why