0

I am new to coding and I am trying to extend \TCG\Voyager\Models\User and Authenticatable implements MustVerifyEmail together but I do not know how to do it.

I have tried class User extends \TCG\Voyager\Models\User, Authenticatable implements MustVerifyEmail together but that doesn't work for me.

I have created 2 seperate classes and that does not let me either.


namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements MustVerifyEmail extends \TCG\Voyager\Models\User
{
    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',
    ];
}
Kenny Horna
  • 13,485
  • 4
  • 44
  • 71
Sang Nguyen
  • 167
  • 1
  • 9
  • Possible duplicate of [Can I extend a class using more than 1 class in PHP?](https://stackoverflow.com/questions/356128/can-i-extend-a-class-using-more-than-1-class-in-php) – rjdown Oct 23 '19 at 21:31

1 Answers1

0

You can't extend two (or more) classes in PHP, just one. A solution could be:

  • Class A extends Class B
  • Class B extends Class C

This way, Class A would also be extending Class C (through Class B).

In your case:

  • User extends \TCG\Voyager\Models\User and implements MustVerifyEmail
  • \TCG\Voyager\Models\User extends Authenticatable

This is one of the reasons, Traits were introduced in the PHP world (are not the same though).

Kenny Horna
  • 13,485
  • 4
  • 44
  • 71