laravel - Automatically update attribute when another attribute is updated -


I have a model bucket with two attributes: name And slug .

name can be a string, and slug is a favorable version of the URL name . Users can update a bucket name , but should be automatically generated by calling slug . Here is my controller code.

  $ bucket = eth :: user () - & gt; Bucket () - & gt; Search ($ id); If (! $ Bucket) Back App: Expiry (404, 'Bucket Not Found'); $ Bucket- & gt; Fill (Input :: All ()); $ Bucket- & gt; Save (); Return $ Bucket;  

With the given code, name is not updated but slug does not. Whenever name changes slog ?

You can try it with a model event:

  Bucket :: update (function ($ bucket) {$ bucket-> slug = $ bucket-> slug; return true;});  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -