Press "Enter" to skip to content

Mutator in Laravel

Sharing is caring!

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.

Be First to Comment

    Leave a Reply

    Your email address will not be published.