mercredi 15 juin 2022

$request->route() returns null in laravel

I have this code:

class TotersProviderLoginController extends Controller
{

    private $oauthService;

    public function __construct(Request $request)
    {
        $provider = $request->route()->parameter('provider'); // error here
        if($provider == 'google')
            $this->oauthService = new GoogleOauthService();
        else
            throw new \Exception('Provider '.($provider ?? '').' not supported!');
    }

I have the following routes defined:

Route::get('login/toters/{provider}', 'Accounts\TotersProviderLoginController@redirectToProvider');
Route::get('login/toters/{provider}/redirect', 'Accounts\TotersProviderLoginController@handleProviderCallback');
Route::get('login/toters/{provider}/csrf', 'Accounts\TotersProviderLoginController@getCsrf');
Route::post('login/toters/{provider}/oauth', 'Accounts\TotersProviderLoginController@requestToken');
    

for some reason when I run

php artisan route:list --verbose

I get this error

In TotersProviderLoginController.php line 38:

  [Symfony\Component\Debug\Exception\FatalThrowableError]
  Call to a member function parameter() on null

so it's clear that $request->route() is returning null. Why is that? note: I'm using Laravel 5.8



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire