Skip to main content

Code Examples of accessors

Discover how to use Laravel's accessors method in real-world applications. Browse 13 examples from popular open-source projects.

13 examples
You use Eloquent Accessors when you want to get some Model field but transform it to be viewed in some other way. Examples: money formatting, date formatting, some calculated field based on a few other fields.
To create such transformation method in your Model, just create function getFieldAttribute() and then you will access your new field like $model->field.
Read more in the official Laravel docs.

bytefury/crater

  • 8295
  • Created Nov 2019
  • Updated Aug 2024

Files in this example

  • app/Models/Payment.php
    • resources/views/app/pdf/payment/payment.blade.php
View full example

serversideup/financial-freedom

  • 2874
  • Created Mar 2021
  • Updated May 2026

Files in this example

  • app/Models/Transactions/Transaction.php
    • resources/js/Pages/Transactions/Show/components/Breakdown.vue
View full example

pelican-dev/panel

  • 2111
  • Created Mar 2024
  • Updated Jun 2026

Files in this example

  • app/Models/Allocation.php
    • app/Http/Controllers/Api/Client/Servers/NetworkAllocationController.php
View full example

academico-sis/academico

  • 371
  • Created Dec 2018
  • Updated Jun 2026

Files in this example

  • app/Models/Skills/Skill.php
    • app/Http/Controllers/Admin/EvaluationTypeCrudController.php
View full example

tighten/novapackages

  • 336
  • Created Feb 2020
  • Updated Jun 2026

Files in this example

  • app/Package.php
    • app/Http/Controllers/PackageController.php
      • resources/views/collaborators/package-card.blade.php
View full example

luadotsh/lua

  • 333
  • Created Oct 2024
  • Updated Apr 2026

Files in this example

  • app/Models/User.php
    • resources/js/Components/UserAvatar.vue
View full example

LaravelDaily/Laravel-Support-Ticketing

  • 300
  • Created Nov 2019
  • Updated Mar 2023

Files in this example

  • app/Ticket.php
    • resources/views/admin/tickets/show.blade.php
View full example

LaraBug/larabug-app

  • 218
  • Created Apr 2021
  • Updated Oct 2023

Files in this example

  • app/Models/Exception.php
    • resources/views/home.blade.php
      • app/Http/Resources/Api/ExceptionResource.php
View full example

alighasemzadeh/bap

  • 154
  • Created Oct 2021
  • Updated Jun 2024

Files in this example

  • app/Models/User.php
    • resources/views/livewire/admin/user/index.blade.php
View full example

nabilhassen/larasense

  • 63
  • Created Nov 2024
  • Updated Jun 2026

Files in this example

  • app/Models/User.php
    • resources/views/livewire/user-avatar.blade.php
View full example

amitavroy/doctor-app

  • 41
  • Created Sep 2021
  • Updated Jan 2022

Files in this example

  • app/Models/Patient.php
    • resources/js/Pages/AppointmentAdd.tsx
View full example

ammannbe/RecipeManager

  • 38
  • Created Dec 2018
  • Updated Dec 2025

Files in this example

  • app/Models/Ingredients/Ingredient.php
    • resources/js/views/Recipe/Ingredient/Ingredient.vue
View full example

JuanDMeGon/Laravel-from-Scratch

  • 18
  • Created Apr 2020
  • Updated Mar 2021

Files in this example

  • app/Product.php
    • resources/views/components/product-card.blade.php
View full example