在使用图片Laravel 5.4更新时尝试获取非对象的属性

时间:2019-06-03 06:25:57

标签: php laravel-5.4

我在上传图片时一直遇到这种情况,但出现“尝试在第1175行获取非对象的属性”错误。我不知道为什么,这是代码。

 public function updateClaimStatus(Request $request) 
{
    $claimreward = ClaimReward::where('id', $request->id)
            ->where('user_id', \Auth::user()->id)->first();
    $rules = [
                'photo' => 'required',
                'feedback' => 'required'
            ];
    $validator = Validator::make($request->all(),$rules);
    if ($validator->passes()){
        $thumb = "";
        if ($request->photo) {

            $name = $claimreward->code.'-'. time() . '.jpg';
            $base64 = substr($request->photo, strpos($request->photo,',')+1);

            // This saves the base64encoded destinationPath
            file_put_contents(storage_path() . '/uploads/' . $name, base64_decode($base64));

            $file = storage_path() . '/uploads/' . $name;
            $thumb = 'thumb_' . $name;

            $image = Image::make($file)->encode('jpg')->orientate()->fit(200)->save(storage_path() . '/uploads/' . $thumb);

            $claimreward->picture = '/uploads/' . $name;
            $claimreward->status = 1;
            $claimreward->processed_by = \Auth::user()->id;
            $claimreward->feedback = $request->feedback;
            $claimreward->save();
            return  response()->json(['success' => true,'message' => 'Status successfully updated']);
    }
        else{
            return  response()->json(['success' => false,'message' => 'Request already accepted']);
        }
    }else{
        return ['error' => $validator->errors()];
    }
}

1175上的行是此行:

$name = $claimreward->code.'-'. time() . '.jpg';

我为什么会遇到此错误的任何想法?

0 个答案:

没有答案