Running an update statement within a Model

Posted 8 months ago by bigweld86

If I'm running a update statement within a model do I have to get the instance of that model again? or can I simply do something like $this->update()?


class MyModel extends Model {

    public function test($id)
        $obj = MyModel::find($id);
        $obj->update(['myField' => 'test']);

or there is any 'simplified' way of doing it, since the method will be called from an existing instance of the object? ie:

class MyModel extends Model {

    public function test()
        $this->update(['myField' => 'test']);


Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.