Не работает аксессор Laravel
Создал модель для получения пользователя. Все данные из таблицы идут хорошо. Мне нужно добаить свойство в объект Auth::user() которого нет в таблице.
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use HasFactory, Notifiable;
protected $table = "ipscore_members";
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'email',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'pass',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [];
protected $appends = [ 'custom' ];
public function getCustomAttribute()
{
return 'Custom attribute';
}
}
В web.php пытаюсь получить это свойство которое добавил через аксессор
Route::get('/', function () {
dump(Auth::user()->custom);
return view('welcome');
})->middleware('auth')->name('main');
На экране получаю сообщение
ErrorException
Undefined index: custom
Подскажите пожалуйста, что делаю не так.