Answer the question
In order to leave comments, you need to log in
How to update an entry in Laravel?
There is such a plate
Model:
class Result extends Eloquent
{
protected $table = 'assets_to_users';
protected $fillable = ['user_id', 'result'];
public function asset()
{
return $this->hasOne('Application\Models\Asset', 'id', 'asset_id');
}
}
$asset_id = 2;
Result::updateOrCreate(
['asset_id' => $asset_id],
['result' => 100]
);
$model = Result::where('asset_id', '=', $asset_id)->first();
echo $model->id; //122
Answer the question
In order to leave comments, you need to log in
You misunderstand the purpose of the updateOrCreate function.
In your case, you need to get an instance of the Result object, and then make changes to it.
$model = Result::where('asset_id', '=', $asset_id)->first();
$model->result = 100;
$model->save();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question