# Laravel Eloquent ORM Accessor ```php= <?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class User extends Model { /** * Get the user's first name. * * @param string $value * @return string */ public function getFirstNameAttribute($value) // 駝峰式命名 { return ucfirst($value); } } ``` 當我們嘗試檢索 `$user->first_name`, Eloquent 會自動調用 `getFirstNameAttribute($value`)。 ```php= $user = App\Models\User::find(1); $firstName = $user->first_name; ``` [參考資料](https://laravel.com/docs/8.x/eloquent-mutators#defining-an-accessor) ###### tags: `Laravel`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up