I am trying to set up a random default value for a Laravel model so that when a user registers a random value is saved to the database for each user.
I've looked at similar question on StackOverflow which explains how to setup a default value using the $attributes variable but it doesn't explain the random bit.
For bind a field default when save model follow this
Override the
save
method of your model:You're not providing enough info, so I'm giving you a solution: you can use a MUTATOR in your User Model:
Where "random_string" is the column in your user table that holds the value. In this way each time you set the "random_string" property of a Model it's automatically set as defined. You simply use it like this: