charlieBrown
3 years ago
1619
5
Laravel

Uploading multiple files not passing foreach

Posted 3 years ago by charlieBrown

I'm here after a lot of search and I have not come to a fix yet. I'm trying to upload several files but it's not getting pass the foreach loop.

/*
         * Validator here. The 'file.*' indicates it's an array.
         */
        $this->validate($request, [
            'file'        => 'required',
            'file.*'      => 'image|mimes:jpg,png|max:5000',
        ]);

        if($request->hasFile('file')){
            $images = $request->file('file');
            //I have confirmed that the code doesn't enter the foorloop and the $images is not empty
            foreach($images as $image){
                $filename = time().'.'.$image->getClientOriginalExtension();
                Image::make($image)->resize(300,300)->save(public_path('images/'.$filename));
            }
        }
$request->session()->flash('alert-success', 'House uploaded sucessully. After validation you will receive an email.');
        return view('addHouse', array('user' => Auth::user()));

Please sign in or create an account to participate in this conversation.