예제 #1
0
 /** 
  * observe cluster event saving
  * 1. modify path
  * 2. check slug
  * 3. act, accept or refuse
  * 
  * @param $model
  * @return bool
  */
 public function saving($model)
 {
     //1.modify slug
     if (isset($model->category_id) && $model->category_id != 0) {
         $model->slug = Str::slug($model->cluster->name . ' ' . $model->name);
     } else {
         $model->slug = Str::slug($model->name);
     }
     if (is_null($model->id)) {
         $id = 0;
     } else {
         $id = $model->id;
     }
     //2. check slug
     $category = Cluster::slug($model->slug)->notid($id)->first();
     if ($category) {
         $model['errors'] = 'Kategori/tag sudah terdaftar.';
         return false;
     }
     return true;
 }