setting the timezone for a user's session on login instead of every request checking and setting

This commit is contained in:
2022-05-20 13:51:37 -06:00
parent b87104c22d
commit 6241539cb3
3 changed files with 117 additions and 0 deletions

View File

@ -0,0 +1,33 @@
<?php
namespace App\Listeners;
use Illuminate\Auth\Events\Login;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Session;
class SuccessfulLogin
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param \Illuminate\Auth\Events\Login $event
*
* @return void
*/
public function handle(Login $event): void
{
Session::put('timezone_name', $event->user->timezone_name);
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Listeners;
use Illuminate\Auth\Events\Logout;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Session;
class SuccessfulLogout
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param \Illuminate\Auth\Events\Logout $event
* @return void
*/
public function handle(Logout $event)
{
Session::forget('timezone_name');
}
}