Examples of Accessors (10)

Short information about accessors

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.

Repository: bytefury/crater (Github)
★ 6212 Created: Nov 2019 Updated: Aug 2022 Laravel version: 8
Files in the example:
- app/Models/Payment.php
- resources/views/app/pdf/payment/payment.blade.php
Repository: serversideup/financial-freedom (Github)
★ 420 Created: Mar 2021 Updated: Jul 2022 Laravel version: 8
Files in the example:
- app/Models/Transactions/Transaction.php
- resources/js/Pages/Transactions/Show/components/Breakdown.vue
Repository: tighten/novapackages (Github)
★ 305 Created: Feb 2020 Updated: Aug 2022 Laravel version: 8
Files in the example:
- app/Package.php
- app/Http/Controllers/PackageController.php
- resources/views/collaborators/package-card.blade.php
Repository: LaravelDaily/Laravel-Support-Ticketing (Github)
★ 195 Created: Nov 2019 Updated: Mar 2021 Laravel version: 8
Files in the example:
- app/Ticket.php
- resources/views/admin/tickets/show.blade.php
Repository: LaraBug/larabug-app (Github)
★ 190 Created: Apr 2021 Updated: Jul 2022 Laravel version: 8
Files in the example:
- app/Models/Exception.php
- resources/views/home.blade.php
- app/Http/Resources/Api/ExceptionResource.php
Repository: academico-sis/academico (Github)
★ 126 Created: Dec 2018 Updated: Aug 2022 Laravel version: 8
Files in the example:
- app/Models/Skills/Skill.php
- app/Http/Controllers/Admin/EvaluationTypeCrudController.php
Repository: alighasemzadeh/bap (Github)
★ 56 Created: Oct 2021 Updated: Jun 2022 Laravel version: 8
Files in the example:
- app/Models/User.php
- resources/views/livewire/admin/user/index.blade.php
Repository: ammannbe/RecipeManager (Github)
★ 31 Created: Dec 2018 Updated: Aug 2021 Laravel version: 8
Files in the example:
- app/Models/Ingredients/Ingredient.php
- resources/js/views/Recipe/Ingredient/Ingredient.vue
Repository: amitavroy/doctor-app (Github)
★ 20 Created: Sep 2021 Updated: Jan 2022 Laravel version: 8
Files in the example:
- app/Models/Patient.php
- resources/js/Pages/AppointmentAdd.tsx
Repository: JuanDMeGon/Laravel-from-Scratch (Github)
★ 11 Created: Apr 2020 Updated: Mar 2021 Laravel version: 8
Files in the example:
- app/Product.php
- resources/views/components/product-card.blade.php

Additional resources on accessors: