Press "Enter" to skip to content

Mutator in Laravel

What is wrong with this mutator method in laravel?

When accessing it like this,

It will end with an error, where it says cannot call save method on null.

Behind the scene, the setAttribute expects $this to be returned. But on mutator, we did not return $this. So, if not returned anything, the result returned would be a null.

So, remember this.

Similarly, if you end up with error ‘Indirect modification of overloaded property App\User::$attribute has no effect’.

You probably need to check your mutator method for error like these.

 

Everything is awesome.

2 Comments

    Leave a Reply

    Your email address will not be published.