Reputation: 180
Hi guys is it possible to do following code in one way?
$Project->deadline()->delete();
$Project->deadline()->create($deadline);
Project Model:
public function deadline()
{
return $this->hasOne('App\Models\UserProjectDeadline','projects_id','id');
}
Upvotes: 0
Views: 87
Reputation: 86
Seems there's no methods for deleting and creating in one line of code, but Laravel offer functions updateOrCreate(array $attributes, array $values = [])
that can be used for hasOne relationships.
$Project->deadline()->updateOrCreate($attributes, $deadline); // To update based on the attributes
Or if you want to change/update all the data without any specified attributes
$Project->deadline()->updateOrCreate([], $deadline); // To update all the data
Upvotes: 3