I have a student form on Laravel 5.5 where users can add as many hobbies as they can. Each hobby has Title, Description & Image. I want to save all Hobbies
. How can I save these information?
My view
<form action="/" method="post" enctype="multipart/form-data" files="true">
<input name="feat[]" type="text" placeholder="Feat 1">
<textarea name="feat_desc[]" placeholder="Feat 1 Desc">
<input type="file" name="feat_img[]">
<input name="feat2" type="text" placeholder="Feat 2">
<textarea name="feat2desc" placeholder="Feat 2 Desc">
<input type="file" name="feat2img">
<button>Add New Hobby</button>
JQuery for dynamic fields
$('#add-form').click(function() {
i++;
$('#add-me').append(
'<input id="quantity" type="text" name="feat[]">'
'<textarea name="feat_desc[]">'
'<input type="file" name="feat_img[]">'
);
});
My Controller:
public function create($Request $requst, Student $student)
$posts = Student::create([
'name' => request('name'),
'interests' => request('interests'),
'hobbies' => json_encode(request('hobbies')),
]);
return redirect ('/');
My database migration
{
Schema::create('students', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('interests');
$table->text('hobbies');
$table->timestamps();
});
}