Right now I have a form with gender, options and user_id.
My public function store (Request $request)
looks like this :
public function store(Request $request)
{
$task = new Appointment;
$task->gender = $request->gender;
$task->options = $request->options;
$task->user_id = $request->user_id;
$task->save();
}
This works completely fine but this is just 3 fields ?! Eventually I want my forms 5 times bigger. My function will be huge. Is there a way to save everything with less code?
I found this : $data = Input::all();
This gets all the data but I don't know how to save it in the database.
You can use mass assignment feature by using create()
method:
public function store(Request $request)
{
Appointment::create($request->all());
}
Don't forget to fill all columns in $fillable
array in Appointment
model:
protected $fillable = ['gender', 'options', 'user_id', 'another_one'];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With