miso

Override Model::setRawAttributes

Posted 3 years ago by miso

I want to have setRawAttributes private/protected, but Laravel does not let me declare setRawAttributes as protected/public. I tried this hack, but this does not work...

class Mymodel extends Model {

    public function setRawAttributes(array $attributes, $sync = false)
    {
        if ($this instanceof Mymodel){ // I want $this to be Model
            throw new \Exception('setRawAttributes is not supported.');
        }
        return parent::setRawAttributes($attributes, $sync);
    }

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

Reply to

Use Markdown with GitHub-flavored code blocks.