I was looking for the right solution to this problem and although there is a lot of information I don't realize how to develop the solution.
It happens to me when I am with a logged in user and the session expires, how can I redirect to the login instead of showing this error?
Trying to get property 'id' of non-object
Error produced in:
@livewire('panel.zooms-component', ['usuarioid' => Auth::user()->id])
utilization:
public $usuarioId;
public function mount($usuarioid = '')
{
$this->usuarioId = $usuarioid;
}
public function render()
{
$contactos = Property::with('contactos')->where('user_id', $this->usuarioId)->get();
// dd($contactos);
return view('livewire.panel.mis-contactos-component', [
'contactos' => $contactos
]);
}
Is there a way in Laravel to indicate that when the session expires, redirect the user to login?
EDITION
It may be so?
Route::group(['middleware' => 'auth'], function () {
Route::get('/', function () {
// Uses Auth Middleware
});
The Route that is pointing to these (methods, functions or controller) is not under a middleware('auth'), implement a middleware.
this Facade
Auth::user()->id
is only enabled if it meets this.you can solve it in the route by adding the middleware('auth')