Exemple #1
0
 public static function boot()
 {
     parent::boot();
     // cause a delete of a category to cascade to children so they are also deleted
     static::deleted(function ($category) {
         $posts = BlogPost::where('category_id', '=', $category->id)->get();
         if (!empty($posts)) {
             foreach ($posts as $post) {
                 $comments = Comment::where('on_post', '=', $post->id);
                 $comments->delete();
             }
             $category->posts()->delete();
         }
     });
 }
 public function search($input, $n)
 {
     $result = BlogPost::selectRaw("*, MATCH(title, body) AGAINST('{$input}' IN BOOLEAN MODE) as pertinence")->whereRaw("MATCH(title, body) AGAINST('{$input}' IN BOOLEAN MODE)")->where('active', '=', true)->orderByRaw("pertinence DESC")->paginate($n);
     return $result;
 }