Call to undefined method save() in laravel update code
In my code am trying to update the information but I receive error as
Call to undefined method IlluminateDatabaseQueryBuilder::save()
$user_id is not a primary key for preferences table. Its just a column name
Controller code for update:
public function update(Request $request, preferences $preferences,$user_id)
{
$preferences = preferences::where('user_id', $user_id);
// $preferences = DB::table('preferences')->where('preferences.user_id','=', $user_id)->first();
$preferences->detergent= request()->detergent;
$preferences->fabricsoftener= request()->fabricsoftener;
$preferences->starch= request()->starch;
$preferences->save();
return redirect()->route('user.home.preferences', [Auth::user()->id]);
}
View code in blade file looks like
<form class="form-group coupon-form" action="" method="post">
<div class="col-md-12">
<div class="heading-title-alt text-left heading-border-bottom">
<h4 class="text-uppercase">Cleaning preferences</h4>
</div>
@foreach($preferences as $preferences)
<div class="form-group">
<label>Detergent</label>
<select name="detergent" class="form-control">
<option name="detergent" value="none" @if ($preferences->detergent == "none") selected @else "" @endif > None</option>
<option name="detergent" value="scented" @if ($preferences->detergent == "scented") selected @else "" @endif >Scented</option>
<option name="detergent" value="hypoallergenic" @if ($preferences->detergent == "hypoallergenic") selected @else "" @endif>Hypo-Allergenic</option>
</select>
</div>
<div class="form-group">
<label>Fabric Softener</label>
<select name="fabricsoftener" class="form-control">
<option name="fabricsoftener" value="yes" @if ($preferences->fabricsoftener == "yes") selected @else "" @endif>Yes</option>
<option name="fabricsoftener" value="no" @if ($preferences->fabricsoftener == "no") selected @else "" @endif>No</option>
</select>
</div>
<div class="form-group">
<label>Starch (Laundered & Press items only)</label>
<select name="starch" class="form-control">
<option name="starch" value="none" @if ($preferences->starch == "none") selected @else "" @endif>None</option>
<option name="starch" value="light" @if ($preferences->starch == "light") selected @else "" @endif>Light</option>
<option name="starch" value="medium" @if ($preferences->starch == "medium") selected @else "" @endif>Medium</option>
<option name="starch" value="heavy" @if ($preferences->starch == "heavy") selected @else "" @endif>Heavy</option>
</select>
</div>
@endforeach
<button class="btn btn-small btn-dark-solid full-width " id="login-form-submit" name="login-form-submit" value="login">Update</button>
</div>
</form>
Please help me understad the error and solve it.
from Laravel Questions and Answers https://laravelquestions.com/laravel/call-to-undefined-method-save-in-laravel-update-code/
via Lzo Media
No comments:
Post a Comment