I have in my database a column called permission
that dictates the permissions of users on my system. User 1 is an administrator and user 0 is not.
The problem is that when I save a new user and select by selecting the user's permission type, it saves all user data except the permission
field which is a int(11)
. What could be happening?
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!');
}
}