This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

n30h.slyfo4920
n30h.slyfo4920

I'd like to extend the the backend form submit process, with adding values before saving items to the database, but i couldnt find any solutions for this problem.

Scott
Scott

What you want is a model event, specifically beforeSave()

class Foo extends Model {
    public function beforeSave()
    {
        // do stuff
    }
}
n30h.slyfo4920
n30h.slyfo4920

Great it works, but i cant acces file from fileupload $this->file returns with NULL

Scott
Scott

I believe file attachments are on a deferred binding. This means that when the model fires it's beforeSave() method, the related files are not attached yet. A better place to try and access these from would be the afterSave() method.

ademin
ademin

If you need to access photos, afterSave() won't help you. Use formAfterSave in your controller. For example to count number of added photos (just an example):

public function formAfterSave($model)
{
    $model->update(['photo_count' => $model->photos()->count()]);
} 

Last updated

1-5 of 5

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.