In Laravel 5.2
, i have added my Event Listener (into app\Providers\EventServiceProvider.php
), like:
protected $listen = [
'Illuminate\Auth\Events\Login' => ['App\Listeners\UserLoggedIn'],
];
Then generated it:
php artisan event:generate
Then in the Event Listener file itself app/Listeners/UserLoggedIn.php
, it's like:
<?php
namespace App\Listeners;
use App\Listeners\Request;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Auth\Events\Login;
class UserLoggedIn
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
}
/**
* Handle the event.
*
* @param Login $event
* @return void
*/
public function handle(Login $event, Request $request)
{
$request->session()->put('test', 'hello world!');
}
}
This shows me following Errors:
ErrorException in UserLoggedIn.php line 28:
Argument 2 passed to App\Listeners\UserLoggedIn::handle() must be an instance of App\Listeners\Request, none given
What did i miss, or how can i solve this please?
- Ultimately, i need to write into Laravel Sessions once the User has logged in.
Thank you all.
routes.php
file. Instead, once inside the Event Handlers, i have to do your way. Am i right please? – Provincetown