В моем коде я пытаюсь обновить информацию, но я получаю сообщение об ошибке как
Call to undefined method Illuminate\Database\Query\Builder::save()
$ user_id не является первичным ключом для таблицы предпочтений. Это просто имя столбца
Код контроллера для обновления:
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]);
}
Вид кода в блейд-файле выглядит как
<form class="form-group coupon-form" action="{{ route('user.home.preferencesupdate', ['user_id' => Auth::id()]) }}" method="post">
{{ csrf_field() }}
<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>
Пожалуйста, помогите мне понять ошибку и решить ее.