- Srijan Pal
- Posts : 5
Join date : 2020-07-30
Getting an error named Class 'AppModelsUser' not found
Thu Jul 30, 2020 5:51 pm
After installing laravel ui in the machine and after that when I am trying to register in the form which was created in laravel after installing laravel ui package it is showing error as: Class '\App\Models\User' not found.
- aboutakashsah
- Posts : 3
Join date : 2020-07-27
Re: Getting an error named Class '\App\Models\User' not found
Thu Jul 30, 2020 9:16 pm
Go to config/auth.php and change App\User:class to App\Models\User::class.
- Srijan Pal
- Posts : 5
Join date : 2020-07-30
Re: Getting an error named Class '\App\Models\User' not found
Thu Jul 30, 2020 9:51 pm
Its already done by me but it is still not working.
- aboutakashsah
- Posts : 3
Join date : 2020-07-27
Re: Getting an error named Class '\App\Models\User' not found
Thu Jul 30, 2020 10:07 pm
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
Also change the namespace of User.php model
namespace App\Models;
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
Also change the namespace of User.php model
namespace App\Models;
- Srijan Pal
- Posts : 5
Join date : 2020-07-30
Re: Getting an error named Class '\App\Models\User' not found
Thu Jul 30, 2020 10:13 pm
It is still showing the same error.
- ritendubhattacharyya
- Posts : 13
Join date : 2020-07-25
Re: Getting an error named Class '\App\Models\User' not found
Thu Jul 30, 2020 11:19 pm
use this App\User::class
and remember to import that folder using "use App;"
and remember to import that folder using "use App;"
- Jeetbasak54@gmail.com
- Posts : 18
Join date : 2020-07-25
Re: Getting an error named Class '\App\Models\User' not found
Thu Jul 30, 2020 11:39 pm
You can add "use" clause at the top of a controller where you're trying to use the model Like that way shown below..
use App\Models;
And if it's not work use it shown below
use App\Models\User;
And also change the namespace of User.php (which is ur model)
namespace App\Models;
use App\Models;
And if it's not work use it shown below
use App\Models\User;
And also change the namespace of User.php (which is ur model)
namespace App\Models;
- Srijan Pal
- Posts : 5
Join date : 2020-07-30
Re: Getting an error named Class '\App\Models\User' not found
Fri Jul 31, 2020 5:16 pm
Its still not working same error and tried all of the suggestions as mentioned above.
- Jeetbasak54@gmail.com
- Posts : 18
Join date : 2020-07-25
Re: Getting an error named Class '\App\Models\User' not found
Fri Jul 31, 2020 7:37 pm
See the spelling carefully which is user and which is users.
U can give the details code here. So that we can see that and if possible can help u...
U can give the details code here. So that we can see that and if possible can help u...
- Srijan Pal
- Posts : 5
Join date : 2020-07-30
Re: Getting an error named Class '\App\Models\User' not found
Fri Jul 31, 2020 11:04 pm
User.php:
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
/*public function setpasswordAttribute($password)
{
$this ->attributes['password'] = bcrypt('password'); // Mutator
}*/
}
RegisterController.php:
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\Models\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
}
Here is the code of User.php and RegisterController.php.
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
/*public function setpasswordAttribute($password)
{
$this ->attributes['password'] = bcrypt('password'); // Mutator
}*/
}
RegisterController.php:
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\Models\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
}
Here is the code of User.php and RegisterController.php.
Permissions in this forum:
You cannot reply to topics in this forum