Example #1
0
 public function cleanup()
 {
     $prefix = config('larablog.table.prefix');
     // Clean out any old pivot data.
     DB::statement("DELETE {$prefix}_post_tag FROM {$prefix}_post_tag LEFT JOIN {$prefix}_posts ON {$prefix}_post_tag.post_id = {$prefix}_posts.id WHERE NOT({$prefix}_post_tag.post_id = {$prefix}_posts.id AND {$prefix}_posts.status = 'active' AND {$prefix}_posts.type='post')");
     // TODO: convert to eloquent?
     DB::table($prefix . '_tags')->update(['posts_count' => DB::Raw("(SELECT COUNT(*) FROM {$prefix}_post_tag WHERE {$prefix}_post_tag.tag_id = {$prefix}_tags.id)")]);
     Tag::where('posts_count', 0)->delete();
 }
Example #2
0
 public static function tags()
 {
     return Tag::orderBy('slug', 'asc')->get();
 }