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

Method break after calling function in same controller

我做了一个处理图像的方法。问题是我想在我的 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);
}