I have a problem updating the information in a role. In my database I have the attribute nombre_rol
as unique
. Registering a new role works perfectly, but when updating the same record, it gives me the error that the Role element is already in use.
Role Model
class Rol extends Model
{
protected $table = 'rol';
protected $primaryKey = 'idrol';
public $timestamps =false;
protected $fillable =['nombre_rol, descripcion, estado, fecha'];
protected $guarded =[];
}
RolRequest
public function rules()
{
return [
'nombre_rol'=>'required|unique:Rol,nombre_rol',
'descripcion'=>'required'
];
}
I am using laravel 5.2 and according to the documentation it says that to ignore I must place the following
'email' => 'nombre_rol'=>'required|unique:Rol,nombre_rol,'.$user->id.',user_id',
But in my case I get an undefined variable error, I do not even understand where I get the variable $ user- > id.