Comments (1)
Disagreed with this.
Traits are a form of inheritance, so whatever behavior your trait(s) supply should be thought of as attached to the model itself. So this is really the same thing as the model having this method directly.
Magic accessors are a performance issue, and they make for an exceptionally confusing API. Why? Because nowhere on your model or your database will you find a property called "fullName". If you don't know what it's implemented as a magic accessor, you'll be tearing your hair out wondering where the fuck $user->fullname is coming from. It also kills IDE support, AND kills the ability to define interfaces.
Traits which depend on properties of their children inherently couple them to their children, but do not provide a sane mechanism for requiring that their children have that behavior present. Abstract classes exist because they can define a "relationship contract" whereby their children MUST implement methods that they (the abstract class) rely on (e.g. for the template method pattern). But traits have no such mechanism. This means that splitting code out of a class and into a trait is splitting code for the sake of splitting it, and not merely to better encapsulate responsibility.
A better way to handle presenters is via a decorator or a simple formatting class.
$user = new UserPresenter($user);
$user->getFullName();
or
UserPresenter::getFullName($user);
from presenter.
Related Issues (20)
- access to relationship model from presenter HOT 3
- Using a constructor in the Presenter Class HOT 2
- Readme not mentioning that presenters path must be inn ClassLoader HOT 3
- Presenter model inside email blade template
- column status cannot read HOT 1
- Using Presenter with lists() method HOT 5
- presenter on cached data.
- Support for Laravel 5 HOT 6
- Cannot use underscore for attributes
- Install instructions HOT 2
- Support for multiple presenters HOT 1
- Can't use function name in Presenter which is equal to the name of the property HOT 3
- Compatible in Laravel 5.2? HOT 2
- This package still has support? HOT 9
- Laravel 6 support HOT 1
- Support for Laravel 9
- Larvel 9.0 is not supported HOT 1
- Would you consider supporting DI for the presenters?
- Please set the $presenter property to your presenter path.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from presenter.