如何扩展User.php的多种功能
我不熟悉编码,我正在尝试扩展如何扩展User.php的多种功能,php,laravel,laravel-6,Php,Laravel,Laravel 6,我不熟悉编码,我正在尝试扩展\TCG\Voyager\Models\User和authenticable同时实现MustVerifyEmail,但我不知道如何做到这一点 我试过classUser扩展\TCG\Voyager\Models\User,authenticable一起实现MustVerifyEmail,但这对我不起作用 我已经创建了两个独立的类,这也不允许我 namespace App; use Illuminate\Notifications\Notifiable; use Il
\TCG\Voyager\Models\User
和authenticable
同时实现MustVerifyEmail
,但我不知道如何做到这一点
我试过classUser
扩展\TCG\Voyager\Models\User
,authenticable
一起实现MustVerifyEmail
,但这对我不起作用
我已经创建了两个独立的类,这也不允许我
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',
];
}
在PHP
中不能扩展两个(或更多)类,只能扩展一个。解决办法可以是:
扩展A类
B类
扩展B类
C类
A类
也将扩展C类
(通过B类
)
就你而言:
扩展了User
并实现了\TCG\Voyager\Models\User
MustVerifyEmail
extends\TCG\Voyager\Models\User
authenticable
这是其中一个原因,特性是在PHP世界中引入的(虽然不一样)。可能重复的特性,那么我将如何编写它。我是新手,所以很难理解。