-
app/Providers/EventServiceProvider.php
Open in GitHubuse Illuminate\Auth\Events\Failed; use App\Listeners\FailedLoginListener; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; class EventServiceProvider extends ServiceProvider { protected $listen = [ // Failed::class => [ FailedLoginListener::class, ], // ]; // }
-
app/Listeners/FailedLoginListener.php
Open in GitHubuse App\Models\FailedLoginAttempt; use App\Models\Group; use App\Notifications\FailedLogin; class FailedLoginListener { public function handle($event) { $bannedGroup = \cache()->rememberForever('banned_group', fn () => Group::where('slug', '=', 'banned')->pluck('id')); if (\property_exists($event, 'user') && $event->user !== null && $event->user instanceof \Illuminate\Database\Eloquent\Model && $event->user->group_id !== $bannedGroup[0]) { FailedLoginAttempt::record( $event->user, \request()->input('username'), \request()->ip() ); $event->user->notify(new FailedLogin( \request()->ip() )); } } }