I have issues with the php error when I tried to insert data for admin using the tinker. I'm creating a multi authentication user which is one for user and one for admin.
PHP Error: Class 'Illuminate/Foundation/Auth/Admin' not found in c:/S/htdocs/i-V/app/Models/Admin.php on line 13
How do I resolve that error?
Admin
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\Admin as Authenticatable;
use Illuminate\Notifications\Notifiable;
use App\Notifications\AdminResetPasswordNotification;
class Admin extends Authenticatable
{
use HasFactory, Notifiable;
protected $guard = 'admin';
/**
* 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',
];
}
I have tried to remove the composer.lock file then install it again
also I have done this.
composer dump-autoload
composer install --no-scripts
composer update
Change this
use Illuminate\Foundation\Auth\Admin as Authenticatable;
to
use Illuminate\Foundation\Auth\User as Authenticatable;
as Illuminate\Foundation\Auth\User it is core code from laravel core and it don't have Admin class
Related
Apologies in advance if I've missed any posting etiquette. Also to note I'm a novice PHP developer.
I'm working on an Instagram clone project from freecodecamp.org on youtube. It's titled: 'Laravel PHP Framework Tutorial - Full Course for Beginners (2019)'. I'm working through sections 1:08:30 - 1:09:30 (video timestamps). I've had everything working up until the profilecontroller was modified to display the username dynamically on the profile page.
Here are the relevant code snippets that I've been working on and that are being referenced in the traceback:
Error:
Error
Class 'App\User' not found
http://localhost:8000/profile/1
App\Http\Controllers\ProfilesController::index
C:\Users\Blake\freeCodeGram\app\Http\Controllers\ProfilesController.php:13`
Controllers/ProfileController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ProfilesController extends Controller
{
public function index($user)
{
\App\User::find($user);
return view('home',[
'user' => $user,
]);
}
}
Web.php
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/profile/{user}', [App\Http\Controllers\ProfilesController::class, 'index'])-
>name('profile.show');
Models/User.php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* #var array<int, string>
*/
protected $fillable = [
'name',
'email',
'username',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* #var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* #var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
Thank you for your help!
In your controller, change the user model from \App\User to App\Models\User.
Then make sure the value of $user passed in \App\Models\User::find($user) should be an integer or array of integers.
I have defined a field location as Spatial in a model that extends a Voyager model. But I keep getting a BadMethodCallException
Call to undefined method TCG\Voyager\Models\User::getCoordinates()
when I try to access the BREAD.
Here is the Model:
<?php
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use TCG\Voyager\Traits\Spatial;
class User extends \TCG\Voyager\Models\User
{
use Notifiable;
use Spatial;
/**
* 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',
];
/**
* Map Coordinate fields
*/
protected $spatial = [
'location'
];
}
I have also tried setting the location column to type GEOMETRY and POINT in the schema. But I suspect that has nothing to do with this.
I'm using Laravel 7 and Voyager 1.4
You can't have two lines with use. This should solve the problem.
class User extends \TCG\Voyager\Models\User
{
use Notifiable, Spatial;
...
I just downloaded a search class for laravel called laravelista/comments
The documentation is pretty scanty so I do not really understand everything.
Basically,when I try to after typing in my details in and pressing submit in'localhost:8000/login' it directs me to laravel PrettyPageHandler and shows me this error:
Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN)
Trait 'Laravelista\Comments\Comments\Traits\Comments' not found
I have already downloaded laravelista/comments and run all the commands like:
php artisan vendor:publish --provider="Laravelista\Comments\Providers\CommentsServiceProvider" --tag=migrations
php artisan migrate
php artisan vendor:publish --provider="Laravelista\Comments\Providers\CommentsServiceProvider" --tag=config
php artisan vendor:publish --provider="Laravelista\Comments\Providers\CommentsServiceProvider" --tag=public --force
but I still get that error
In my User.php:
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravelista\Comments\Comments\Traits\Comments;
class User extends Authenticatable
{
use Notifiable;
use Comments;
/**
* 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',
];
}
Please help.
I just had to change User.php to
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravelista\Comments\Commenter;
class User extends Authenticatable
{
use Notifiable,Commenter;
/**
* 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',
];
}
I used the wrong use
I'm using the library Bican Roles. I change User.php for:
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Bican\Roles\Traits\HasRoleAndPermission;
use Bican\Roles\Contracts\HasRoleAndPermission as HasRoleAndPermissionContract;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract, HasRoleAndPermissionContract
{
use Authenticatable, CanResetPassword, HasRoleAndPermission,Notifiable;
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'name', 'surnames', 'email', 'password','phone',
];
/**
* The attributes that should be hidden for arrays.
*
* #var array
*/
protected $hidden = [
'password', 'remember_token',
];
}
When try to register a new userthrow the following error:
Class 'App \ Model' not found
I have tried to add it
use User;
etc but still not working, any ideas? Thank you
You need to add
use Illuminate\Database\Eloquent\Model;
to the top of your class declaration, not use User;
The error you're getting is
Class 'App \ Model' not found
not
Class 'User' not found
try
use Illuminate\Database\Eloquent\Model;
I'm having an error when seeding to the database using laravel 5.5 the error message is below and there is my users class and my seeder class. What is happening is that one record is being inserted at a time when calling db:seed but after the first call it says BadMethodException rest below
[BadMethodCallException]
Call to undefined method App\User::create()
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Zizaco\Entrust\Traits\EntrustUserTrait;
use Eloquent;
class User extends Eloquent
{
use EntrustUserTrait;
/**
* 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',
];
}
<?php
use App\User;
use Faker\Factory as Faker;
use Illuminate\Database\Seeder;
class UsersTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* #return void
*/
public function run()
{
foreach (range(1, 100) as $index) {
$faker = Faker::create();
$user = User::create([
'name' => $faker->firstName . ' ' . $faker->lastName,
'email' => $faker->email,
'password' => bcrypt('secret')
]);
}
}
}
Your user model should extend
\Illuminate\Database\Eloquent\Model
Or
\Illuminate\Foundation\Auth\User
You are extending Eloquent
laravel/laravel repository: https://github.com/laravel/laravel/blob/master/app/User.php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
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',
];
}
Your User class needs to extend to Model class
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
...
}
EDIT
This is my User
<?php namespace App;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract {
use Authenticatable, CanResetPassword;
protected $table = 'users';
protected $fillable = ['name', 'email', 'password'];
protected $hidden = ['password', 'remember_token'];
}
Hope it helps!