Examples of Accessors (8)

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)
★ 4133 Created: Nov 2019 Updated: Jul 2021 Laravel version: 8
Files in the example:
- app/Models/Payment.php
- resources/views/app/pdf/payment/payment.blade.php
Repository: tighten/novapackages (Github)
★ 202 Created: Feb 2020 Updated: Jul 2021 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)
★ 152 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)
★ 125 Created: Apr 2021 Updated: Jun 2021 Laravel version: 8
Files in the example:
- app/Models/Exception.php
- resources/views/home.blade.php
- app/Http/Resources/Api/ExceptionResource.php
Repository: serversideup/financial-freedom (Github)
★ 88 Created: Mar 2021 Updated: Oct 2021 Laravel version: 8
Files in the example:
- app/Models/Transactions/Transaction.php
- resources/js/Pages/Transactions/Show/components/Breakdown.vue
Repository: academico-sis/academico (Github)
★ 45 Created: Dec 2018 Updated: Aug 2021 Laravel version: 8
Files in the example:
- app/Models/Skills/Skill.php
- app/Http/Controllers/Admin/EvaluationTypeCrudController.php
Repository: ammannbe/RecipeManager (Github)
★ 19 Created: Dec 2018 Updated: Feb 2021 Laravel version: 8
Files in the example:
- app/Models/Ingredients/Ingredient.php
- resources/js/views/Recipe/Ingredient/Ingredient.vue
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: