0
Good afternoon,
I want to add the type field to the user of a system in Laravel and am doing 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 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 don’t understand why