1

I am trying to update the setting but unfortunately, I am facing an error on how to fix this error? please help me thanks.

please see error https://flareapp.io/share/yPaYdGP4

Controller

public function settingupdate(Request $request)
{
    $input = $request->except('_token','logo_image');
    if ($request->logo_image) {
        $setting = Settings::where('key','logo_image')->first();
        $input['logo_image'] = $request->logo_image;
        $input['logo_image'] = Storage::disk('cms')->putFile('', $request->file('logo_image'));
        $request->file('logo_image');
    }

    foreach($input as $key => $value) {    
        $setting = Settings::where('key',$key)->first();
        $setting->value = $value;
        $setting->save();
    }

    return back()->with('success', 'Setting Successfully updated')- >with('path',$setting);
}

1 Answer 1

1

You are getting error because of below line. This line returning no record and you are setting value on it $setting->value = $value

$setting = Settings::where('key',$key)->first();

To resolve this you can check whether data exist or not

    $setting = Settings::where('key',$key)->first();
    if ($setting !== null) { // add this
        $setting->value = $value;
        $setting->save();
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.