Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

How to get the IP address from an authentication event?

Hello,

I have a few authentication events with listeners, for example 'Illuminate\Auth\Events\Failed': https://laravel.com/api/10.x/Illuminate/Auth/Events/Failed.html

I want to get the IP address from it, but since there is no request here I cant use $request->ip().

Is there any way to pass the request to the event?

Thanks

0 likes
3 replies
MichalOravec's avatar
Level 75

Use request() helper:

$ip = request()->ip();
1 like
Ligonsker's avatar

@MichalOravec Ah, after yesterday's post I was thinking in terms of injecting classes, and I was about to say to inject Request $request to the __construct() of the Listener:

public function __construct(Request $request){...}

Made me completely forget about helpers :D

thanks!

Ligonsker's avatar

@MichalOravec update: it might not be the best solution. If I have an async queue, then the request help might not have the relevant request but the last request handled by the app.

I think I should then create my own event and dispatch it. Now I just need to find out at which point in the login process in the LoginController does Laravel dispatch these events. Where can I find it?

Please or to participate in this conversation.