user3233787
user3233787

Reputation: 377

Laravel Jetstream Custom Authentication Login Process Pass Request

I've been reading and following jetstream's documentation and I wanted to create a custom class for the authentication process:

If you prefer to encapsulate your custom authentication process within a class instead of a closure, you may pass a PHP "callable" array to the authenticateUsing method:

use App\Actions\AuthenticateLoginAttempt;
use Laravel\Fortify\Fortify;

Fortify::authenticateUsing([new AuthenticateLoginAttempt, '__invoke']);

I have already created the file AuthenticateLoginAttempt in App/Actions folder:

<?php

namespace App\Actions;

class AuthenticateLoginAttempt
{
    public function __invoke()
    {

    }
}

What I wanted is also to pass the Request $request as an argument that will be used later in the __invoke magic method:

Fortify::authenticateUsing([new AuthenticateLoginAttempt, '__invoke', ...Request $request...]);

public function __invoke(Request $request)
{
    
}

How to achieve this one? It seems to me that their documentation is unclear to me. Thank you.

Upvotes: 1

Views: 371

Answers (1)

cvairlis
cvairlis

Reputation: 41

Hello it doesn't work as explained in Jetstream documentation?

You should simply do as it is described:

Fortify::authenticateUsing([new AuthenticateLoginAttempt, '__invoke']);

And after this inside the __invoke function of the new class, you should receive the request object.

public function __invoke(Request $request)
{
    dd($request);
}

Upvotes: 0

Related Questions