Questions tagged [mutators]

Anything related to mutators (a.k.a. setters, or mutator methods) in object oriented programming, i.e. instance methods whose exclusive purpose is to change (part of) the internal state of an object to a specific value, without performing substantial additional processing.. This may also refer to mutator functions in non-OO languages when OOP techniques are used to emulate OOP-like encapsulation.

Overview

Anything related to mutators (a.k.a. setters, or mutator/setter methods) in Object Oriented Programming, i.e. instance methods whose exclusive purpose is to change (part of) the internal state of an object to a specific value, without performing substantial additional processing. This may also refer to mutator functions in non-OO languages when OOP techniques are used to emulate OOP-like encapsulation.

See also

217 questions
4
votes
1 answer

Laravel protected attributes and Mutators

I have some problem with laravel and protected $attributes and mutators. I have user ranking with points. I want add to User Model another attribution with ranking Position. In user model I have public function like this: public function…
Mateusz Kaleta
  • 137
  • 2
  • 10
4
votes
4 answers

Laravel Modify collection data

I wonder if Laravel have any helper to modify a collection. What I need to do is to make a query with paginate() then check if the logged in users ID match the sender or reciever and based on that add a new value to the output: $userId =…
user2636197
  • 3,432
  • 6
  • 40
  • 64
4
votes
1 answer

Mutator is not working with bulk insertation

I am trying to insert multiple record in laravel by using Order::insert($orderArray); I have made a mutator that is public function setOrderDetailAttribute($value) { if ($value) { $this->attributes['order_detail'] =…
Umar Akbar
  • 93
  • 1
  • 7
4
votes
0 answers

Pitest, Spring Boot, Gradle Plugin Error

I am currently trying to add Mutation testing to a gradle project. I have successfully added it on a simple test project that purely has a noddy test class but I cannot seem to add it into the main project. After much searching I have found no…
KirisuteRanza
  • 367
  • 4
  • 14
4
votes
1 answer

Using accessor mutator with a belongsTo relationship

Using Laravel 4 and I have a mutator set up in my User model: public function getFullnameAttribute($value) { return $this->first_name. ' ' .$this->last_name; } But I have a relationship set up in my Cars model for a user ID linked to that…
Lovelock
  • 6,609
  • 15
  • 71
  • 162
4
votes
2 answers

Accessor & Mutator methods (Python)

I am trying to figure out encapsulation in Python. I was doing a simple little test in shell to see how something worked and it doesn't work like I was expecting. And I can't get it to work. Here's my code: class Car: def __init__(self,…
user2255444
  • 43
  • 1
  • 1
  • 3
4
votes
3 answers

Can class default public variables be defined dynamically from an array in php?

I have a event class that i am using to insert/update data into my database. Is there a way that i can create the public variables from my db_fields array so that i am not having to duplicate the data? This is my current structure which…
3
votes
3 answers

Protected mutators (setters)

Problem Suppose you have a class user. You want to be able to return this user object to others so they can use it to extract information using getters. However, you don't want people to be able to readily set the internal state because the internal…
3
votes
2 answers

Using .splice method in subclass of Array in javascript?

I am trying to create a subclass of javascript's Array. I want to initiate subclass with array-type argument and add a method to remove an element from the array (subclass). My code looks like this: class CustomArray extends Array { …
ands
  • 1,463
  • 11
  • 21
3
votes
2 answers

JSON column passed to view as string - Laravel - Vuejs2

I'm passing a Laravel Model's dataset to a vuejs2 component via ajax/ axiom and rendering it fine. However, there is a JSON column in the model which stores a valid json object, the data could look like so: {'key':'value'} and it's worth noting…
Lewis
  • 485
  • 7
  • 14
3
votes
1 answer

LARAVEL Payload is invalid error but decrypted data is correct

Recently i made new project with composer and added very basic authentication with make:auth - nothing fancy. Next i wanted to encrypt name and email columns on my database so i changed their types from VARCHAR(191) to LONGTEXT and added some very…
180doman
  • 87
  • 1
  • 1
  • 10
3
votes
1 answer

laravel problems with mutators

My journey into laravel 4 (from laravel 3) continues.... I have an Article model, accessing a table called articles. I have set up the model with the following mutators: class Article extends Eloquent { public function…
Ray
  • 2,818
  • 6
  • 44
  • 88
2
votes
2 answers

How to pass values using setter and getter among three classes

I've been practicing a project which is the classical Nim game. What I've achieved now is: Add, remove, edit, display, players. (Nimsys and NimPlayer) Selecting two players to play a game. (NimGame class) Every time when the game ends, I need to…
Woden
  • 510
  • 3
  • 9
2
votes
2 answers

How to Get Data From Model in Function With Laravel

Is it possible to get data from the model in a function? I want to get the SupplierID data from the Product model. public function productAjax($id) { $product = new Producttext(); $products = $product->productexts($id); $hitung_products…
Jazuly
  • 1,184
  • 1
  • 13
  • 29
2
votes
2 answers

Clarification with eager loading/mutators/accessors for laravel

I'm making a laravel app for work and I need to load all users with their attached role without any nesting of the roles. I used this tutorial for roles:…
Brad Goldsmith
  • 243
  • 3
  • 17
1
2
3
14 15