Rock
Rock

Reputation: 395

Class App\User contains 6 abstract methods and must therefore be declared abstract

I saw this error for the first time and don't really know what to do about it. When I tried to register a new user on my website and when I clicked on submit button it shows:

FatalErrorException in User.php line 11: Class App\User contains 6 abstract methods and must therefore be declared abstract or implement the remaining methods (Illuminate\Contracts\Auth\Authenticatable::getAuthIdentifierName, Illuminate\Contracts\Auth\Authenticatable::getAuthIdentifier, Illuminate\Contracts\Auth\Authenticatable::getAuthPassword, ...)

User Model:

<?php 
namespace App;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;

class User extends Model implements Authenticatable
{
protected $table = 'users';
protected $primaryKey = 'id';   
}

What is it trying to say, I don't understand. Please can someone help me with this?

Upvotes: 2

Views: 14531

Answers (2)

Avik Aghajanyan
Avik Aghajanyan

Reputation: 1023

You need to either extend Illuminate\Foundation\Auth\User instead of Illuminate\Database\Eloquent\Model, or use Illuminate\Auth\Authenticatable trait in your class

UPDATE

You need to extend Illuminate\Foundation\Auth\User like this

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{

} 

UPDATE 2

Also make sure you don't have native Laravel's App\User model in you app folder, named User.php

Upvotes: 7

zgabievi
zgabievi

Reputation: 1202

You are implementing Illuminate\Contracts\Auth\Authenticatable. This is interface and requires your User class to have some required methods:

public function getAuthIdentifierName();
public function getAuthIdentifier();
public function getAuthPassword();
public function getRememberToken();
public function setRememberToken($value);
public function getRememberTokenName();

If you are trying to make default User model, you should use Illuminate\Foundation\Auth\User as Authenticatable and extend it instead of Model class. There is no need to implement Authenticatable interfase.

Upvotes: 10

Related Questions