laravel-jwt icon indicating copy to clipboard operation
laravel-jwt copied to clipboard

BindingResolutionException

Open podluzhnyi opened this issue 8 years ago • 7 comments

After installation strictly according to the instructions, I have a exception:

Unresolvable dependency resolving [Parameter #0 [ $app ]] in class Codecasts\Auth\JWT\Auth\Guard in Container.php (line 910)

Laravel 5.4.28

I did:

  1. composer require codecasts/laravel-jwt
  2. added service provider Codecasts\Auth\JWT\ServiceProvider::class
  3. published vendor files
  4. generated and added secret to .env
  5. changed driver in api guards to 'jwt'

podluzhnyi avatar Aug 07 '17 14:08 podluzhnyi

Same here

pedrogaldino avatar Oct 26 '17 15:10 pedrogaldino

@podluzhnyi @pedrogaldino gonna check it right now

hernandev avatar Oct 28 '17 07:10 hernandev

@pedrogaldino @pedrogaldino can you explain better where are you triggering this?

The Guard instance should be registered on the laravel and it's not instantiable with resolve since it needs some parameters.

the other guards, default ones are the same

hernandev avatar Oct 28 '17 12:10 hernandev

@podluzhnyi @pedrogaldino @hernandev - did you guys ever find the cause of this? I'm experiencing this exact same issue on Laravel 5.6 / PHP 7.2.

phillip-elm avatar Apr 21 '18 23:04 phillip-elm

Just came back from running some errands - took a fresh look at this, I think I figure out what @hernandev meant - this error went away in my code when I stopped trying to have the Guard DI'd into my controller and instead used the Auth facade.

Example:

// This won't even run - the DI will fail. This is adapted from the current README.md.
public function refreshToken(Guard $auth, Request $request)
{
  $token = $auth->refresh();
  return response()->json(compact('token'));
}

Instead, running the following works:

public function refreshToken(Request $request)
{
  $token = \Auth::refresh();
  return response()->json(compact('token'));
}

Once I switched to the latter method, all my tests passed. As such, we probably want to update the README. I'll submit a PR.

phillip-elm avatar Apr 22 '18 03:04 phillip-elm

I'm rather new to laravel but this looks kind of fishy to me:

https://github.com/codecasts/laravel-jwt/blob/cd5cf11d4f5be42cbf2d1202612779e84c13a980/src/Auth/ServiceProvider.php#L42-L49

Is there any reason a fresh guard is returned and not $guard ?

Anticom avatar Nov 23 '18 15:11 Anticom

@Anticom I have already fixed this in PR https://github.com/codecasts/laravel-jwt/pull/45. @hernandev returning a new instance of the guard resulted in the Auth events not being fired (bug), I fixed that in my PR, but now because Laravel 5.7 changed the events constructor, the package need to be updated for 5.7 also.

This means the next release of the package will be for >= 5.7 only

jonagoldman avatar Nov 23 '18 18:11 jonagoldman