Hello Jessica Ervin, Multiple image upload is very easy and i hope you will enjoy it after learning this and access from public folder. but From internet i found there are many recommendation about store the folder in storage folder. so you have to create link storage folder in your public folder. its called "symlink".
For example: suppose you are creating an app for Gallery picture. so you need one album. and that album contains multiple image
You need to create storage link first
php artisan storage:link
After run this command you will find a folder in your public folder called "storage"
create a folder in storage. suppose i am named this folder 'images'
Now from view (something.blade.php) create your form.
<form method="post" action="{{route('gallery.store')}}" enctype="multipart/form-data">
@csrf
<input type="file" name="image[]" class="form-control" required multiple accept="'image/*">
<input type="submit" value="Save">
</form>
Now go to your controller page (in my case its GalleryController)
public function store(Request $request)
{
$image_get = $request->image;
foreach ($image_get as $image) {
$fileOriginalName = $image->getClientOriginalExtension();
$fileNewName = time() .'.'. $fileOriginalName;
$image->storeAs('images', $fileNewName, 'public'); //here images is folder, $fileNewName is files new name, public indicated public folder. that means folder this image in public/storage/images folder
Gallery::create([
'album' => $request->album,
'image' => $fileNewName
]);
}
return redirect()->back()->with('message', 'Photos Added');
}
Now how to access this image from view
create function
public function index()
{
$gallerys = gallery::orderBY('id', 'desc')->get();
return view('index', compact('gallerys'));
}
go to your blade file. suppose index.blade.php
@foreach($gallerys as $gallery)
<img src="{{asset('/storage/images/'.$gallery->image)}}" alt="">
@endforeach
Is there any other need comment here
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community