In Laravel 5.2, i need to do something while the authentication process is being triggered. (Not "after" the login.)
Here are what i have done.
In EventServiceProvider.php:
protected $listen = [
'Illuminate\Auth\Events\Attempting' => ['App\Listeners\UserLoginAttempt@handle'],
];
In app/Listeners/UserLoginAttempt.php:
<?php
namespace App\Listeners;
use Illuminate\Http\Request;
use Illuminate\Auth\Events\Login;
use Carbon\Carbon;
use Auth;
class UserLoginAttempt
{
public function __construct()
{
}
public function handle($event)
{
dd(Auth::user());
exit;
}
}
This always returns null.
** In fact, i have one "custom" field in the Login form, of which i need to capture from the above Event Handler. (I need to check something before actual Login event is done.)
- How do i capture the
Auth::user()from this (Illuminate\Auth\Events\Attempting) Handler please? - (In other words) How do i talk with the Login Form from the (Illuminate\Auth\Events\Attempting) Handler?
- OR ----- Is the
Auth::user()object created ONLY AFTER the login is fully processed? Which means i can not get it while in "attempting" stage?
Because i need to capture the login elements first, and if it is something "unauthorized" (after some calculations done in Handler), then i need to terminate the login attempt and route back to the login form from here.. by carrying the Failing Message along.
Please let me know what i'm missing here. Thank you.
Auth::user()object created once user is authenticated. - Abbasi$_GET["my_custom_field"]like this ugly?) - 夏期劇場Requeste.g.$my_custom_field = $request->input('my_custom_field');if you provide your controller method where you are trying to achieve this would be quite easy to guide further. - Abbasi