diff --git a/app/EventActions/UpdateQuestionHashtags.php b/app/EventActions/UpdateQuestionHashtags.php index 49ca4306a..7e143ee4f 100644 --- a/app/EventActions/UpdateQuestionHashtags.php +++ b/app/EventActions/UpdateQuestionHashtags.php @@ -6,6 +6,7 @@ use App\Models\Hashtag; use App\Models\Question; +use Carbon\Carbon; use Illuminate\Support\Collection; use Illuminate\Support\Str; @@ -26,9 +27,12 @@ public function __construct( public function handle(): array { $parsedHashtags = $this->parsedHashtagNames(); - + $existingHashtags = Hashtag::query()->whereIn('name', $parsedHashtags->all())->get(); + // Update udated at that particular hashtag used so it should be updated time + Hashtag::query()->whereIn('name', $parsedHashtags->all())->update(['updated_at' => Carbon::now()]); + $newHashtags = $parsedHashtags->diff($existingHashtags->pluck('name')) ->map(fn (string $name): Hashtag => Hashtag::query()->create(['name' => $name])); diff --git a/app/Livewire/Home/TrendingHashtags.php b/app/Livewire/Home/TrendingHashtags.php new file mode 100644 index 000000000..dfe9bcf63 --- /dev/null +++ b/app/Livewire/Home/TrendingHashtags.php @@ -0,0 +1,21 @@ +withCount(['questions' => function (Builder $query) { + $query->where('created_at', '>=', now()->subDays(1)); + }]) + ->where('updated_at', '>=', now()->subDays(1))->limit(5)->orderBy('questions_count', 'DESC')->get(); + return view('livewire.home.trending-hashtags', ['hashtags' => $hashtags]); + } +} diff --git a/app/Queries/Feeds/TrendingHashtags.php b/app/Queries/Feeds/TrendingHashtags.php new file mode 100644 index 000000000..a81c1b70f --- /dev/null +++ b/app/Queries/Feeds/TrendingHashtags.php @@ -0,0 +1,31 @@ + + */ + public function builder(): Builder + { + $maxDaysSincePosted = self::MAX_DAYS_SINCE_POSTED; + + return Hashtag::query() + ->withCount('questions') + ->where('created_at', '>=', now()->subDays($maxDaysSincePosted)); + } +} diff --git a/resources/views/home/trending-questions.blade.php b/resources/views/home/trending-questions.blade.php index 489f2eab1..02c401ef2 100644 --- a/resources/views/home/trending-questions.blade.php +++ b/resources/views/home/trending-questions.blade.php @@ -3,6 +3,7 @@
+
diff --git a/resources/views/layouts/navigation.blade.php b/resources/views/layouts/navigation.blade.php index cbf478df4..8489de99e 100644 --- a/resources/views/layouts/navigation.blade.php +++ b/resources/views/layouts/navigation.blade.php @@ -5,7 +5,7 @@