【问题标题】:How to extend multiple things for User.php如何为 User.php 扩展多个东西
【发布时间】:2019-10-23 21:29:39
【问题描述】:

我是编码新手,我正在尝试扩展 \TCG\Voyager\Models\UserAuthenticatable 一起实现 MustVerifyEmail,但我不知道该怎么做。

我尝试了User 类扩展\TCG\Voyager\Models\UserAuthenticatable 一起实现MustVerifyEmail,但这对我不起作用。

我已经创建了 2 个单独的类,但我也没有。


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 laravel laravel-6


【解决方案1】:

您不能在PHP 中扩展两个(或更多)类,只能扩展一个。解决方案可能是:

  • Class A 扩展 Class B
  • Class B 扩展 Class C

这样,Class A 也将扩展 Class C(通过 Class B)。

在你的情况下:

  • User 扩展 \TCG\Voyager\Models\User 并实现 MustVerifyEmail
  • \TCG\Voyager\Models\User 扩展 Authenticatable

这是原因之一,在 PHP 世界中引入了 Traits(虽然不一样)。

【讨论】:

  • 那我该怎么写呢。我是新手,所以很难理解。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-07-08
  • 1970-01-01
  • 1970-01-01
  • 2010-09-30
  • 2012-01-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多