Level 75
It would be better to have a related images table. Or if 5 is the most you will have five separate columns instead of just one column.
Could use a simple Loop in view to display the images.
Edit: also see my answer here
Hi, I need in My form attach maximum 1-5 images without refresh one by one and save in one column all images I have following ImageGalleryController.php. but it is upload one image per one saving and save one images in the column. I need modify this upload maximam 5 images and saving images in one column.
ImageGalleryController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\ImageGallery;
class ImageGalleryController extends Controller
{
/**
* Listing Of images gallery
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$images = ImageGallery::get();
return view('image-gallery',compact('images'));
}
/**
* Upload image function
*
* @return \Illuminate\Http\Response
*/
public function upload(Request $request)
{
$this->validate($request, [
'title' => 'required',
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
$input['image'] = time().'.'.$request->image->getClientOriginalExtension();
$request->image->move(public_path('images'), $input['image']);
$input['title'] = $request->title;
ImageGallery::create($input);
return back()
->with('success','Image Uploaded successfully.');
}
/**
* Remove Image function
*
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
ImageGallery::find($id)->delete();
return back()
->with('success','Image removed successfully.');
}
}
Please or to participate in this conversation.