Hey,
when I want to use namespaced model
config.php from tymon/jwt-auth
'user' => 'Api\Entities\User'
it says
class \User not found
and doesn't work until I add alias to
app.php
'User' => 'Api\Entities\User',
what might be the problem?
What code are you running to trigger the exception?
Hi, I have the same problem, I googled a lot, but I didn't find anything useful
ReflectionException in Container.php line 776:
Class App\User does not exist
In file config.php of this library, I have the same namespace than auth.php
laravel auth.php:
'model' => 'Backend\User',
jwt config.php:
'user' => 'Backend\User',
The piece of code that is returning this error is like the example in the docs
class UserController extends Controller
{
public function login()
{
$credentials = Input::only('email', 'password');
if (!$token = JWTAuth::attempt($credentials)) {
return Response::json(['error' => 'invalid_credentials'], 401);
}
return Response::json(compact('token'));
}
Am I missing something in the configuration of JWT?
Thanks
ok, thanks for the extra info. I will try to reproduce this later today
struggling to reproduce this tbh... there's only one place that this is referenced. And it seems likely that this would have been raised by others if it was an issue with the package
Is this still an issue for you ?
It's totally fixable... You have to change the model in Laravel (4.2) auth.php to Namespace\User
Then it will work
Did you get to the end of this? Im getting the same error on Lara 5
.ignore - I just needed to amend config/jwt.php line 67 amended the User path. Sorted.
I also have the same problem, i.e I have created a separate namespace for models as App\Models\User and even though I have changed model name in jwt config.php as below :
'user' => 'App\Models\User'
I am getting below error:
local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class '\App\User' not found' in /var/www/html/dsa/backend/vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php:1
26
and doesn't work until I update
laravel auth.php:
'model' => App\Models\User::class
+1 @olso
why have to update laravel auth.php 'model' => App\Models\User,doesn't laravel use JWT to authenticate?
I'm having the same issue and changing the namespace in auth and jwt config makes no difference.
Hi, I have recently started learning Laravel-5 and i am developing rest web service. To make api secure i am using JWT. I am facing the same issue as stated above.
I have moved the user class from "App\User" to "App\Models\User" and i have added following code in jwt.php
'user' => 'App\Models\User', // code in jwt.php
Inside my Controller Action i have written following code
public function signIn(SignInRequestValidationRules $request)
{
$credentials = $request->only('email', 'password');
try {
if(! $token = JWTAuth::attempt($credentials)) {
return response()->json(['error' => 'invalid_credentials'], 401);
}
} catch (JWTException $e) {
return response()->json(['error' => 'could_not_create_token'], 500);
}
return response()->json(compact('token'));
}
Now whenever i am accessing signIn action using postman i am getting the following exception message.
"Class 'App\User' not found At Line 130 in E:\xampp\htdocs\laravel-rest-service\vendor\laravelframework\src\IlluminateAuth\EloquentUserProvider.php"
Kindly provide your valuable inputs.
@sanchitpuri13
It looks cache/autoload issue:
composer dump-autoload
php artisan clear-compiled
and then restart your server. Just search the "App\User" in your project to get better idea
@ganeshghalame thanks for giving your valuable time.
I tried the same but the issue still remains, but at end i found the solution. I am providing the link of solution, which can be used by others as well.
https://github.com/jenssegers/laravel-mongodb/issues/702.
Rest the changes needs to be done in Auth.php to replace App\User to App\Models\User and same in Jwt.php. I have also replaces all the Occurence of App\User to App\Models\User Project wide as there is no class App\User in my project anymore.
For anyone that is here looking for solution, I ran into this because I had my class as a string. In config/jwt.php change:
'user' => '\App\Models\User'
to
/*
|--------------------------------------------------------------------------
| User Model namespace
|--------------------------------------------------------------------------
|
| Specify the full namespace to your User model.
| e.g. 'Acme\Entities\User'
|
*/
'user' => \App\Models\User::class,
Most helpful comment
Hi, I have the same problem, I googled a lot, but I didn't find anything useful
In file config.php of this library, I have the same namespace than auth.php
laravel auth.php:
jwt config.php:
The piece of code that is returning this error is like the example in the docs
Am I missing something in the configuration of JWT?
Thanks