Skip to content
Advertisement

Create a variable for each array item

I have the following code for my post sign up page on my site.

JavaScript

I need to know if it is possible to simplify my code incase I add new sign up options. What I’m trying to do is create a variable for each item in the $request array which can then be used by the $user->sqltable = $sqltableitem

Something like

JavaScript

Is this possible and any other suggestions?

Advertisement

Answer

You don’t need to create a variable for each element. Just use mass assignment feature:

JavaScript

One this clause does exactly the same as all your posted code.

Don’t forget to fill $fillable array:

JavaScript

If you want to bcrypt password manually, the right way to do this will be creating mutator:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement