I've gotten the Solution Thanks Everyone
Jun 4, 2017
3
Level 2
Upload Multiple Images to Server Using Image Intervention
public function saveImages(Request $request)
{
$images = $request->file('hostel_image_files');
$slug = session::get('new_hostel_slug');
$folderName = $slug;
$listingPath = $folderName ."/";
$path = "uploads/listings/hostels/". $folderName ."/";
//File Does not Exist
if(!File::exists($path)) {
File::makeDirectory($path, 0775, true);
}
//Add path to DB
$hostel = Hostel::whereSlug($slug)->first();
if (!is_null($hostel->images_id)) {
$hostel->images_id = $listingPath; // Path to where all listing images resides
$hostel->save();
}
foreach ($images as $key => $image) {
$rules = [
'image' => 'required|image|mimes:jpeg,bmp,png|size:2048' //2MB Max Size
];
$v = Validator::make($image, $rules);
if ($v->fails()) {
return redirect()->back()->withInput()->withErrors($v);
}
$fileName = $image->getClientOriginalName().$image->getClientOriginalExtension();
$destinationPath = $path;
//Upload Images One After the Order into folder
$img = Image::make($request->file('hostel_image_files'));
$img->insert(public_path('img/logo.png'), 'bottom-right', 10, 10)->save($destinationPath.'/'.$fileName);
$move = $image->move($destinationPath, $fileName);
//Insert into DB and
}
return redirect()->route('create_hostel_step5');
}
STACK ERROR LOG
[2017-06-05 04:57:35] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Argument 1 passed to Illuminate\Validation\Factory::make() must be of the type array, object given, called in C:\xampp\htdocs\appname\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 221
I have the above method to upload multiple images and add watermark on it using Image Intervention. This is the error I get while trying to save the image. Please help me out. IF there's another better and more professional and standard way to do it please help me out.
Thanks in Anticipation
Level 2
1 like
Please or to participate in this conversation.