Laravel Eloquent: Virtual Attributes
January 16, 2026
•
1 min read
•
29 views
Table of Contents
Virtual attributes:
Define Accessor
protected function fullName(): Attribute
{
return Attribute::make(
get: fn () => $this->first_name . ' ' . $this->last_name,
);
}
Append to Array
protected $appends = ['full_name'];
Append Dynamically
$user->append('full_name');
$users = User::all()->append('full_name');
Hide from Array
protected $hidden = ['password', 'remember_token'];
$user->makeHidden('email');
$user->makeVisible('password');
Related Posts
Laravel Sanctum API Authentication Complete Guide
Build secure API authentication with Laravel Sanctum for SPAs and mobile apps.
Laravel Rate Limiting: Protect Your Application
Implement rate limiting to protect your Laravel application from abuse.
Laravel Blade Components: Build Reusable UI
Create powerful reusable components with Laravel Blade.
Comments (0)
No comments yet. Be the first to comment!