Reputation: 1355
Trying to make an photo uploader using Intervention\Image I have this in ReportController@store :
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.
Upvotes: 0
Views: 1129
Reputation: 49
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);
}
Upvotes: 1