在同一控制器中调用函数后的方法中断



我做了一个处理图像的方法。问题是我想在我的Edit方法中调用该方法几次,因为有 3 个用于上传图像的按钮。但是在为IMAGE调用我的方法后,EDIT方法会在第一个图像后停止。我怎样才能阻止它?

if($request->has('picture1')) {
return $this->upload_image($company, $asset, $request->picture1);
}
if($request->has('picture2')) {
return $this->upload_image($company, $asset, $request->picture2);
}
if($request->has('picture3')) {
return $this->upload_image($company, $asset, $request->picture2);
}

这是我上传图片的功能

public function upload_image($company, $asset, $image) 
{
$filename = uniqid(rand());
$image = str_replace('data:image/png;base64,', '', $image);
$image = str_replace(' ', '+', $image);
if (!file_exists(public_path('/uploads/assets/pictures/' . $company->id . '/'))) {
File::makeDirectory(public_path('/uploads/assets/pictures/' . $company->id . '/'), 0777, true);
}
Image::make($image)->resize(1024, null, function ($constraint) { $constraint->aspectRatio();})
->save( public_path('/uploads/assets/pictures/' . $company->id . '/'. $filename ) );
}

处理第一个图像后如何返回我的函数?

您必须像这样简单地删除return关键字:

if($request->has('picture1')) {
$this->upload_image($company, $asset, $request->picture1);
}
if($request->has('picture2')) {
$this->upload_image($company, $asset, $request->picture2);
}
if($request->has('picture3')) {
$this->upload_image($company, $asset, $request->picture2);
}

相关内容

  • 没有找到相关文章

最新更新