当我尝试将模型中的属性转换为我的一个枚举时,它会引发错误:
调用未定义的方法 App\Enums\UserType::from()
我找不到有关所需find()
方法的任何信息。
我按照这里的说明进行操作。
我的枚举UserType
:
namespace App\Enums;
enum UserType
{
case CUSTOMER;
case PARTNER;
case ADMIN;
}
我的用户模型:
namespace App\Models;
use App\Enums\UserType;
use FaarenTech\LaravelCustomUuids\Interfaces\HasCustomUuidInterface;
use FaarenTech\LaravelCustomUuids\Models\UuidModel;
use Illuminate\Auth\MustVerifyEmail;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableInterface;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableInterface;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Illuminate\Auth\Authenticatable;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Auth\Passwords\CanResetPassword;
class User extends UuidModel implements
AuthorizableInterface,
AuthenticatableInterface,
CanResetPasswordInterface,
HasCustomUuidInterface
{
use
HasApiTokens,
HasFactory,
Notifiable,
Authenticatable,
Authorizable,
CanResetPassword,
MustVerifyEmail,
SoftDeletes;
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
'type' => UserType::class
];
}