first commit
This commit is contained in:
33
app/Listeners/Auth/Login.php
Normal file
33
app/Listeners/Auth/Login.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Auth;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Auth\Events\Login as ILogin;
|
||||
|
||||
class Login
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param Logout $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(ILogin $event)
|
||||
{
|
||||
// Get company
|
||||
$company = Auth::user()->companies()->first();
|
||||
|
||||
session(['company_id' => $company->id]);
|
||||
}
|
||||
}
|
||||
38
app/Listeners/Auth/Logout.php
Normal file
38
app/Listeners/Auth/Logout.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Auth;
|
||||
|
||||
use Jenssegers\Date\Date;
|
||||
use Illuminate\Auth\Events\Logout as ILogout;
|
||||
|
||||
class Logout
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param Logout $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(ILogout $event)
|
||||
{
|
||||
if (empty($event->user)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->user->last_logged_in_at = Date::now();
|
||||
|
||||
$event->user->save();
|
||||
|
||||
session()->forget('company_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user