1
I have in my database a column called permission
that dictates the permissions of users on my system. User 1 is administrator and user 0 is not.
The problem is that when I save a new user and select through select the type of user permission, it saves all user data, except the field permission
which is a int(11)
. What might be going on?
Migrate
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddPermissionToUsersTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function(Blueprint $table)
{
$table->integer('permission');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function(Blueprint $table)
{
$table->dropColumn('permission');
});
}
}
View
@extends('admin.painel.layout')
@section('conteudoPainel')
<h2>Usuários: [Novo]</h2>
{!! Form::open(['role' => 'form', 'method' => 'POST', 'route' => 'admin.usuarios.store']) !!}
{!! Form::label('Nome') !!}
{!! Form::text('nome', Input::old('nome'), ['class' => 'form-control']) !!}
<br />
{!! Form::label('E-mail') !!}
{!! Form::text('email', Input::old('email'), ['class' => 'form-control']) !!}
<br />
{!! Form::label('Senha') !!}
{!! Form::password('senha', ['class' => 'form-control']) !!}
<br />
{!! Form::label('Permissão') !!}<br />
{!! Form::select('permissao', [0=>'Usuário padrão', 1=>'Administrador'], Input::old('permissao'), ['class'=>'input-sm', 'style'=> 'border: 1px solid #ccc;']) !!}
<br />
<br />
<button type="submit" class="btn btn-success">
<i class="glyphicon glyphicon-floppy-saved"></i> Cadastrar
</button>
<a href="/admin/usuarios" class="btn btn-danger">
<span class="glyphicon glyphicon-remove"></span>
Cancelar
</a>
{!! Form::close() !!}
@stop
Controller
public function store(NewUserFormRequest $request)
{
$data = [
'name' => $request->get('nome'),
'email' => $request->get('email'),
'password' => Hash::make($request->get('senha')),
'permission' => $request->get('permissao')
];
if($user = User::create($data)){
return redirect()->to('admin/usuarios/'.$user->id."/edit")->with(['alertaOk' => 'Usuário cadastrado com sucesso!']);
} else {
return redirect()->to('admin/usuarios')->withErrors('Não foi possivel cadastrar o usuario. Entre em contato com o administrador para mais informações!');
}
}
what returns a
dd($request->get('permissao'))
?– gmsantos
When I select administrator it returns 1, and when I select default user it returns 0. But only saved in database as 0.
– Samuel Carvalho
How is the property
$fillable
in his modelUser
?– gmsantos
protected $fillable = ['name', 'email', 'password'];
– Samuel Carvalho