I want to build secure api application consult of http://www.toptal.com/web/cookie-free-authentication-with-json-web-tokens-an-example-in-laravel-and-angularjs
As far as work great in my routes.php, but when i move this code in my controller
if ( ! $token = JWTAuth::attempt($credentials)) {
return Response::json(false, HttpResponse::HTTP_UNAUTHORIZED);
}
it throw exception like this
Non-static method Tymon\JWTAuth\JWTAuth::attempt() should not be called statically, assuming $this from incompatible context
If you know what is happened , can you tell me what can i do ?
Should i put all the code in my routes?
thanks!
can show all code in yr controller?
You're tying to call attempt() on the JWTAuth class and not the facade. You probably have "use Tymon\JWTAuth\JWTAuth" at the top of your controller. Either remove the use statement or qualify the JWTAuth call from global scope like \JWTAuth::attempt($credentials).
You should also either use the provided middleware/write your own. Or make an Api controller with the check and have all your api classes extend it.
@devmark @jfadich yes
tThe problem is "use Tymon\JWTAuth\JWTAuth" at the top of controller
When it change that of "use JWTAuth;" , it work!
Thank you very much !
@jfadich Thank you! This helped me
Thank you!
Thanks Man
I think we must use "Tymon\JWTAuth\Facades\JWTAuth" instead of "Tymon\JWTAuth\JWTAuth"
When it change that of "use JWTAuth;" , it work!
because we set it in config/app.php
'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class,
Most helpful comment
@devmark @jfadich yes
tThe problem is "use Tymon\JWTAuth\JWTAuth" at the top of controller
When it change that of "use JWTAuth;" , it work!
Thank you very much !