diff --git a/app/DiscoverCategory.php b/app/DiscoverCategory.php new file mode 100644 index 000000000..2112319f2 --- /dev/null +++ b/app/DiscoverCategory.php @@ -0,0 +1,58 @@ +belongsTo(Media::class); + } + + public function url() + { + return url('/discover/c/'.$this->slug); + } + + public function editUrl() + { + return url('/i/admin/discover/category/edit/' . $this->id); + } + + public function thumb() + { + return $this->media->thumb(); + } + + public function items() + { + return $this->hasMany(DiscoverCategoryHashtag::class, 'discover_category_id'); + } + + public function hashtags() + { + return $this->hasManyThrough( + Hashtag::class, + DiscoverCategoryHashtag::class, + 'discover_category_id', + 'id', + 'id', + 'hashtag_id' + ); + } + + public function posts() + { + return Status::select('*') + ->join('status_hashtags', 'statuses.id', '=', 'status_hashtags.status_id') + ->join('hashtags', 'status_hashtags.hashtag_id', '=', 'hashtags.id') + ->join('discover_category_hashtags', 'hashtags.id', '=', 'discover_category_hashtags.hashtag_id') + ->join('discover_categories', 'discover_category_hashtags.discover_category_id', '=', 'discover_categories.id') + ->where('discover_categories.id', $this->id); + } +} diff --git a/app/Http/Controllers/DiscoverCategoryController.php b/app/Http/Controllers/DiscoverCategoryController.php new file mode 100644 index 000000000..bd2869e2c --- /dev/null +++ b/app/Http/Controllers/DiscoverCategoryController.php @@ -0,0 +1,10 @@ +bigIncrements('id'); + $table->string('name')->nullable(); + $table->string('slug')->unique()->index(); + $table->boolean('active')->default(false)->index(); + $table->tinyInteger('order')->unsigned()->default(5); + $table->bigInteger('media_id')->unsigned()->unique()->nullable(); + $table->boolean('no_nsfw')->default(true); + $table->boolean('local_only')->default(true); + $table->boolean('public_only')->default(true); + $table->boolean('photos_only')->default(true); + $table->timestamp('active_until')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('discover_categories'); + } +}