I am loading data from a file excel
to myself base de datos
but in one foranea
I need to call the id
user who is logged in to be able to register it, I am doing it in the following way:
Controller code (import)
public function model(array $row)
{
$id=Auth::tbl_usuario()->usu_id;
$tipo=DB::table('tbl_tipo_instrumento')->select('tipo_id')->where ('tipo_nombre','=',$row[14])->get();
$marca=DB::table('tbl_marca')->select('mar_id')->where('mar_nombre','=',$row[15])->get();
$usu = DB::table('tbl_usuario')->select('usu_id')->where('usuario','=',$row[13])->get();
return new tbl_instrumentos([
'ins_codigo' => $row[0],
'ins_observacionInicial' => $row[4],
'ins_claseOexactitud' => $row[6],
'ins_nSerie' => $row[1],
'ins_divOescala'=>$row[5],
'ins_claseOexactitud' =>$row[6] ,
'ins_consecutivoInterno' => $row[7],
'ins_observaciones' =>$row[8],
'ins_observacionFinal' => $row[9],
'ins_magnitud' => $row[10],
'ins_modelo' => $row[11],
'ins_codActividad' => $row[12],
'ins_area' => 'null',
'ins_usu_id' => $id,
'ins_tipo_id' => $tipo,
'ins_mar_id' => $marca,
]);
But when uploading the file excel
I get the following error:
Method Illuminate\Auth\SessionGuard::tbl_usuario does not exist.
Additionally codigo
, I attach my model:
class tbl_usuario extends Model implements AuthenticatableContract
{
use Authenticatable;
public $timestamps = false;
public $table="tbl_usuario";
}
How can I solve this problem, thanks.
According to the Laravel documentation, the logged in user can be obtained in several ways:
With the Auth facade
in a Request
With the auth() helper (Similar to the first)
In short, using the facade, the request or the helper, the method you should use is
user()