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
2
votes
1 answer

I want to set date into my html date field. I have used mutator in Laravel, Now how can I set date in the date field to edit a record?

This is My mutator in my model.. protected $dates = ['closer_date','final_submission_date','start_date']; This is a field where I want to set the dates in the fields retrieving record from database.
2
votes
1 answer

laravel set Mutator for input array

I have an array input in this format name[{{$lang->code}}] and it give me in run time then i tried to set Mutator for this field as below public function…
Kareem Nour Emam
  • 956
  • 3
  • 12
  • 25
2
votes
2 answers

Convert fname and lname to camel case while saving from model?

I have employees table in which i want to save the fname and lname colomns as camel case no matter the user input using the model. I am using ardent for validations is there any other way for this? I used mutators like bellow but still its saving as…
Sourav
  • 47
  • 1
  • 11
2
votes
0 answers

what is closure in the context of mutator and accessor functions in R?

I am trying to write 2 functions in R, one that creates a matrix and defines mutator and accessor functions (I think that's the right terms) for that matrix and its inverse, and another that operates on the type of objects defined in the first…
user3299824
  • 43
  • 1
  • 4
2
votes
2 answers

Laravel use dynamic mutators in where clause

So i have two columns - SizeX & SizeY. For front end users I use Laravel mutator public function getSizeAttribute(){ /** * Set Size */ $size = $this->SizeX. " x ". $this->SizeY; /** * Return */ return $size; } To…
Vilius
  • 784
  • 1
  • 10
  • 24
2
votes
3 answers

Using Laravel casts and mutators at the same time

This is part of my Role model: namespace App; use App\Traits\Permissions; use Illuminate\Database\Eloquent\Model; class Role extends Model { use Permissions; /** * {@inheritDoc} */ protected $casts = [ 'permissions'…
DanVeira
  • 311
  • 1
  • 4
  • 15
2
votes
3 answers

Laravel Model conditional formatting

I have a database and model called Vote_actions that looks like this: id group_id user_id action_type anonymous (boolean) User can ask to be anonymous (that would make the boolean value to be true).If that is the case, I want to change the…
harveyslash
  • 5,364
  • 8
  • 47
  • 98
2
votes
2 answers

How to pass a variable between methods without parameters and arguments

I'm having a bit of an issue with a school project of mine. We're supposed to write a Loan class that will do things associated with, well, loans, such as return the monthly payment and the total payment on the loan. My problem is that I have…
2
votes
2 answers

Use accessor mutator's within Laravel 4 lists method

I have a simple mutator: public function getFullnameAttribute($value) { return $this->first_name. ' ' .$this->last_name; } But I also have a method that returns a list of specific users for use in a select input: static function…
Lovelock
  • 6,609
  • 15
  • 71
  • 162
2
votes
2 answers

Implode separate date of birth values from php form

Ok i'm out of ideas and have reached the end point in my research. have a registration form with a birthdate select fields example below:
{!! Form::selectMonth('dob_month', 1, ['class'=>…
Rudy Jessop
  • 802
  • 11
  • 22
2
votes
1 answer

How to customize a field of the model before storing in database

I have a model like this : class Article extends Model { protected $fillable = [ 'title', 'body', 'img_profile', // store name of image ]; } And a controller like this: public function store(ArticleRequest $request){ $article =…
Phi Nguyen
  • 2,919
  • 11
  • 24
2
votes
3 answers

Is it a good practice to use set methods in the constructor to initialize class's fields?

I would like to use a class's set methods in the constructor in order to check the values to be initialized, throwing an exception if they do not comply with the constraints I set. code example: public class MyClass { // Fields private int…
pgmank
  • 3,829
  • 2
  • 27
  • 45
2
votes
0 answers

Using the Mutator Method in client program

I just need some clarification whenever i use the Mutator Method in the client program okay so i my employee class set up and i was taught that my variable should be private double salary then have my Accessors then the Mutators and it should be…
tonyisapony
  • 89
  • 2
  • 9
2
votes
2 answers

Best Practice for Jackson collection deserialisation

Let's say I have a simple class Person public class Person{ final List names= Lists.newArrayList(); public List getNames(){ return names; } } If I try to deserialise that with Jackson (2.2) Person l =…
husayt
  • 12,616
  • 7
  • 45
  • 75
1
vote
4 answers

I wrote Accessors and Mutators methods, but still I cant access private variables! why?

I wrote my class with its private variables and then I wrote the accessor and mutator methods needed to access those variables, but that does not work when I run it after writing the main class. Why does that happening ?check my code here : public…
AbdullahR
  • 931
  • 3
  • 11
  • 14
1 2
3
14 15