/** * Make sure that only 1 main page exists * * @param bool $insert * * @return bool */ public function beforeSave($insert) { if (parent::beforeSave($insert)) { if ($this->type == static::TYPE_TEXT) { $this->slug = LittleBigHelper::slug($this->slug ? $this->slug : $this->name); } if ($this->is_main == 1 && ($insert || $this->oldAttributes['is_main'] == 0)) { ContentPage::updateAll(['is_main' => 0]); $this->active = 1; } return true; } return false; }
/** * Create unique code on insert if it's empty * * @param bool $insert * * @return bool */ public function beforeSave($insert) { if ($this->code === null || empty($this->code)) { $this->code = uniqid(); } return parent::beforeSave($insert); }
public function beforeSave($insert) { if (parent::beforeSave($insert)) { if (!$this->code) { $this->code = uniqid(); } return true; } return false; }