Commit 55ad4e9a authored by kapil verma's avatar kapil verma

Added a method to fluently set belongs-to relation

This method spun off from a discussion in IRC. What this enables is this:

$user->comments()->insert($comment_data)->article()->bind($article->id)
parent ec13efb7
......@@ -111,4 +111,20 @@ 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment