This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
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.
What you want is a model event, specifically beforeSave()
class Foo extends Model {
public function beforeSave()
{
// do stuff
}
}
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.
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