diff --git a/laravel/database/eloquent/relationships/belongs_to.php b/laravel/database/eloquent/relationships/belongs_to.php index ef257836..6a2c1116 100644 --- a/laravel/database/eloquent/relationships/belongs_to.php +++ b/laravel/database/eloquent/relationships/belongs_to.php @@ -110,5 +110,21 @@ class Belongs_To extends Relationship { { return $this->base->get_attribute($this->foreign); } + + /** + * Bind an object over a belongs-to relation using its id. + * + * @return Eloquent + */ + + public function bind($id) + { + if((int) $this->foreign_value() === (int) $id) + return $this->base; + + $this->base->fill(array($this->foreign => $id))->save(); + + return $this->base; + } } \ No newline at end of file