Try $projectcommunication->media. = ",".$filename; which is the same as $projectcommunication->media = $projectcommunication->media.",".$filename;
Sep 27, 2016
7
Level 2
Multiple files upload in laravel
I want to upload multiple files and save their path into one column using comma separator, i am trying it but not get 100% result.
Right now images or files are uploaded into path but it save only first file name in db.
here is my form
<form role="form" method="post" action="{{ action('ProjectsController@projectCommunication') }}" enctype="multipart/form-data">
<input type="hidden" name="_token" value="{{ csrf_token()}}">
<div class="form-group">
<label for="message">Enter Comment:</label>
<textarea class="form-control" rows="3" id="message" name="message" placeholder="Enter Comment here!"></textarea>
</div>
<div class="form-group">
<label for="media">Upload File:</label>
<input type="file" class="form-control" name="media[]" id="media" multiple>
</div>
<button class="btn btn-primary">Send</button>
</form>
here is controller code
if($request->file('media'))
{
foreach($request->file('media') as $media)
{
if(!empty($media))
{
$destinationPath = 'uploads/companies/award';
$filename = $media->getClientOriginalName();
$media->move($destinationPath, $filename);
$projectcommunication->media = $filename;
}
}
}
Level 9
1 like
Please or to participate in this conversation.