-
-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat(hashtags): Add hashtag storage and relation syncing #495
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. We probably didn't need a new model / table, parsing would have been enough, however storing the hashtags will mean we can introduce analytics & similar down the track.
Can we add a way to filter the feed by hashtag? Such as:
// Route:
Route::get('/tag/{hashtag}', HashtagController::class)->name('home.hashtag');
// Controller:
class HashtagController
{
public function __invoke(string $hashtag)
{
return view('hashtag.show', [
'hashtag' => $hashtag,
]);
}
}
// View:
<x-app-layout>
<x-slot name="title">Posts with #{{ $hashtag }}</x-slot>
<div class="flex flex-col items-center justify-center">
<div class="w-full max-w-md overflow-hidden rounded-lg px-2 shadow-md sm:px-0">
<x-home-menu></x-home-menu>
@auth
<livewire:questions.create :toId="auth()->id()" />
@endauth
<livewire:home.feed :hashtag="$hashtag" />
</div>
</div>
</x-app-layout>
Then we just need to add a property to the Feed component.
public ?string $hashtag = null;
// Use the property in to filter the feed.
->when($this->hashtag, fn ($query) => $query
->whereHas('hashtags', fn ($query) => $query
->where('name', $this->hashtag)
)
)
Thanks for the review Cam! I do think a model + relations is the way to go here, for a few reasons:
Last but not least, thanks for the blueprint of UI/feed related stuff! As I mentioned up top, the purpose of this PR is solely backend operations to keep it easier to review and break up potentially bugs into separate reverts haha. UI stuff comes next 😁 |
database/migrations/2024_08_07_203106_create_hashtags_table.php
Outdated
Show resolved
Hide resolved
…\UpdateQuestionHashtags
@MrPunyapal I updated this PR based on our discussion:
I believe this is good to go but please give it another look and let me know if you spot any loose ends. I can follow up soon after with the UI PR. |
Our next stop in our hashtag journey is here!
This PR:
Hashtag
model (with migration, factory, etc).There are no UI changes with this PR (that'll come next!). This simply provides the backend processing and storage needed to produce forthcoming UI elements.
100% test coverage, all passing.No phpstan errors.
I am getting some rector failures but it deals with code outside of this PR's changes...
Relates to #371