Regards, I am updating a table called usuarios using the same view where the Primary key = idusuarios, the insert makes me the problem flawlessly is when I want to update it generates the error
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'usuarios.id' in 'where clause' (SQL: select * from usuarios
where usuarios
.id
= 1 limit 1)
this is my code
Model
class Usuario extends Model {
protected $table = 'usuarios';
protected $primarykey = 'idusuarios';
protected $filliable = [ 'cedula','nombre','tele1','tele2','correo','direccion',
'user_name','user_pass','fecha_ingreso','usu_idrol'];
public function Usuario(){
// return $this->belongsTo('app\Roles','idrole','usu_idrol');
return $this->hasOne('app\Roles','idrole','usu_idrol');
}
const CREATED_AT = NULL;
const UPDATED_AT = NULL;
Model of the another table
class Roles extends Model
{
protected $table ='roles';
protected $primarykey = 'idrole';
protected $filliable = ['desc_rol'];
public function Roles(){
return $this->belongsTo('app\Usuario','usu_idrol','idrole');
}
controller
public function update(Request $request)
{
//
$usuario = Usuario::findOrFail($request->idusuarios);
$usuario->cedula = $request ->cedula;
$usuario->nombre = $request ->nombre;
$usuario->tele1 = $request ->tele1;
$usuario->tele2 = $request ->tele2;
$usuario->correo = $request ->correo;
$usuario->direccion = $request ->direccion;
$usuario->user_name = $request ->user_name;
$usuario->user_pass = $request ->user_pass;
$usuario->fecha_ingreso = $request ->fecha_ingreso;
$usuario->estado = $request ->estado;
$usuario->usu_idrol = $request ->usu_idrol;
$usuario->save();
}
axios
actualizarUsuario(){
if (this.validarUsuario()) {
return;
}
let me = this;
axios.put('/usuario/actualizar',{
// parametros que voy a recibir
'idusuarios': this.idusuarios,
'cedula': this.cedula,
'nombre': this.nombre,
'tele1': this.tele1,
'tele2': this.tele2,
'correo': this.correo,
'direccion': this.direccion,
'user_name': this.user_name,
'user_pass': this.user_pass,
'fecha_ingreso': this.fecha_ingreso,
'estado': this.estado,
'usu_idrol': this.usu_idrol,
'idusuarios': this.idusuarios,
}).then(function (response) {
me.cerrarModal();
me.listarUsuario();
}).catch(function (error) {
console.log(error)
});
},