Level 122
you have an input text area and someone types #something
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
is there any best way to create a hashtag feature on laravel
The general idea would be to something like
The tables
hashtags
- id
- title
tweets
- id
- body
hashtag_tweets
- id
- hashtag_id
- tweet_id
The relationships
class Tweet
{
public function hashtags()
{
return $this->belongsToMany(Hashtag::class);
}
}
class Hashtag
{
public function tweets()
{
return $this->belongsToMany(Tweet::class);
}
}
And of course as @snapey suggested, you need to label everything that comes after the symbol # as a hashtag which can be done with regular expressions.
Please or to participate in this conversation.