Skip to content

The issue is a new pattern of Attribute Cast #40230

Closed
@michaelnabil230

Description

@michaelnabil230

I'm using the new version of Attribute Cast in the Laravel version: 8.77 but showed this error when logged in authorization with guard admin

  • Laravel Version: 8.77.1
  • PHP Version: 8.0

Error:

image

Model Admin:

<?php

namespace App\Models\Tenant;

use Illuminate\Database\Eloquent\Casts\Attribute;

class Admin extends Authenticatable
{
    use Notifiable, HasRoles, SoftDeletes;

    /**
     * The authentication guard name.
     *
     * @var string
     */
    public $guard = 'admin';

    /**
     * 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',
    ];
    
    /**
     * Set the admin's Hash password.
     *
     * @return Attribute
     */
    protected function password(): Attribute
    {
        return new Attribute(
            set: fn($value) => Hash::make($value),
        );
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions