Apr 4, 2021
0
Level 3
Multi upload image with alt and label
Hello guys, I have a problem with multiple image upload. Now I have simple upload like this:
if($request->has('photos')) {
foreach ($request->photos as $photo) {
$filename = 'img-'.Str::random(14).'.'.$photo->getClientOriginalExtension();
$photo->storeAs('public/photos/',$filename);
Photo::create([
'page_id' => $page->id,
'filename' => $filename
]);
}
}
and part of view:
<input type="file" name="photos[]" class="file-upload-default d-none" onchange="ValidateSize(this)" id="uploadPhoto" multiple aria-describedby="fileHelp" accept="image/*">
<div class="input-group col-xs-12">
<input type="text" class="form-control file-upload-info" disabled="" placeholder="Load images">
<span class="input-group-append">
<button class="file-upload-browse btn btn-danger" type="button">Load</button>
</span>
</div>
as a result of selecting several images, I get input with the name of a single image. I want to be able to add an alt attribute and a label to all images.
My photos table looks like this:
Schema::create('photos', function (Blueprint $table) {
$table->increments('id');
$table->integer('page_id')->nullable();
$table->string('filename');
$table->integer('order')->unsigned()->default(0);
});
Page is in relationship with Photo - one to many. Does anyone have any idea how to solve this?
Please or to participate in this conversation.