Can I define accessor with model?
See original GitHub issueI want define accessor with model object like Laravel eloquent accessor. https://laravel.com/docs/5.6/eloquent-mutators#accessors-and-mutators
Is it possbile?
export default class Person extends Model {
defaults() {
return {
id: null,
firstName: '',
lastName: ''
};
}
get fullname() {
return `${this.lastName} ${this.firstName} `;
}
}
const person = new Person({firstName: 'Shu', lastName: 'Ogawa'});
console.log(person.fullname); // Ogawa Shu
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How to define an accessor in model where the field name ...
I am trying to define an accessor in my User model for a field which already exists. This field is called address_line_1 in...
Read more >How can I query using Accessor that I defined in Model
How can I query using Accessor that I defined in Model ; public function getStatusAttribute() ; $this->loss == 0 ; $this->loss > $this...
Read more >Model Accessors & Mutators - LdapRecord
Accessors and mutators allow you to modify attribute values when you retrieve or set them on model instances. If you'd ever used Laravel ......
Read more >Laravel 8 - Accessors and Mutators (Eloquent in 2 Steps)
To define an accessor, create a get{Attribute}Attribute method on your model where {Attribute} is the “studly” cased name of the column. Open ...
Read more >Eloquent: Mutators - The PHP Framework For Web Artisans
Accessors and mutators allow you to format Eloquent attribute values when you retrieve or set them on model instances. For example, you may...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sifex Thank you for reply.
I tried. But fullname is empty.
I had check by vue devtool. _mutations is empty object.
Where is wrong?
I made my own
accessors
method, based onmutations
.How to use