php - Saving multiple image input using InterventionImage

528

Trying to make an photo uploader using Intervention\Image I have this in [email protected] :

public function SavePhoto($photo){
        $file_ext = $photo->getClientOriginalExtension();
        $file_name = uniqid();
        $photo_name = $file_name. '.' . $file_ext;
        $path = public_path('uploads/photos/' . $photo_name);
        Image::make($photo)->resize(300, null, function ($constraint) {
            $constraint->aspectRatio();
        })->save($path);
        return $photo_name;
    }

public function store(Request $request)
    {

        $observation = new Observation();
        $observation->content = $request['Observation'];
        $observation->status_id = $request['Status'];
        $photo = Input::file('photo');

        foreach ($photo as $p){
            $this->SavePhoto($p);

        }

I am so confused of how to call the SavePhoto() method for all photos input.

138

Answer

Solution:

According to the Laravel API docs use the allFiles() method to get the files of$request.

$photos = $request->allFiles();
foreach ($photos as $photo){
    $this->SavePhoto($photo);
}

I haven't tried it though. :)
its the equivalent of getting the $_FILES array

foreach($_FILES as $photo) {
    $this->SavePhoto($photo);
}

People are also looking for solutions to the problem: javascript - form not being submitted laravel

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.