Sunday, May 21, 2017

Submit JS array to Eloquent controller

I'm finding it quite difficult to find documentation on how to build Eloquent functions to store data into a MySQL database.

At the moment I can bring a variable into a MySQL database by taking the value from a form field:

$new_character->character_name = request('characterName');

characterName is the ID of a form field.

But I have variables that I want to bring into a new DB row. How do I do this?

I've tried using jquery to assign the array to a form:

<input type="text" class="form-control" id="skillsField">
skillsVar = skillsList.toString(); // skillsVar is an array of strings
$('#skillsField').val(skillsVar);

And then in the Eloquent model:

$new_character->Trained_Skills = request('skillsField');

But this just results in null being submitted to the DB.

Help with the question is appreciated, pointing me to a document that simply explains DB CRUD in Laravel even more so!



via Ruairi McNicholas

Advertisement