I am new to laravel so please guide me, My problem is, I need to store a string and text array in my database in laravel, tho I cannot pass anything inside the database using arrays.. can anyone help me out here please thanks.
Here is my code in View and Controller
My code in View
{!! Form::open(['action'=>'Admin\AboutusController@store', 'method' => 'POST','enctype'=>'multipart/form-data', 'name' => 'add_name', 'id' => 'add_name']) !!}
<div class="form-group">
<div class="table-responsive">
<table class="table table-bordered" id="dynamic_field">
<tr>
<td> {{Form::text('title[]', '', ['class' => 'form-control', 'placeholder' => 'Enter a Title'])}}<br>
{{Form::textarea('description[]', '', ['class' => 'form-control', 'placeholder' => 'Enter a Description'])}} <br>
{{ Form::file('about_image[]') }}
</td>
<td>{{ Form::button('', ['class' => 'btn btn-success fa fa-plus-circle', 'id'=>'add','name'=>'add', 'style'=>'font-size:15px;']) }}</td>
</tr>
</table>
{{Form::submit('submit', ['class'=>'btn btn-primary', 'name'=>'submit'])}}
</div>
</div>
{!! Form::close() !!}
There you can see my textbox, textarea and submit button
My Controller
$this->validate($request, [
'title' => 'required',
'description' => 'required',
'about_image' => 'required'
]);
if ($request->has('about_image'))
{
//Handle File Upload
$about = [];
foreach ($request->file('about_image') as $key => $file)
{
// Get FileName
$filenameWithExt = $file->getClientOriginalName();
//Get just filename
$filename = pathinfo( $filenameWithExt, PATHINFO_FILENAME);
//Get just extension
$extension = $file->getClientOriginalExtension();
//Filename to Store
$fileNameToStore = $filename.'_'.time().'.'.$extension;
//Upload Image
$path = $file->storeAs('public/about_images',$fileNameToStore);
array_push($about, $fileNameToStore);
}
$fileNameToStore = serialize($about);
}
else
{
$fileNameToStore='noimage.jpg';
}
foreach ($about as $key => $value) {
$aboutContent = new About;
$aboutContent->title = $value->input('title');
$aboutContent->description = $value->input('description');
$aboutContent->about_image = $value;
$aboutContent->save();
}