bigweld86
1 year ago

Running an update statement within a Model

Posted 1 year 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()?

Meaning:

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']);
    }
}

Thanks

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