Download the PHP package rennokki/befriended without Composer
On this page you can find all versions of the php package rennokki/befriended. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rennokki/befriended
More information about rennokki/befriended
Files in rennokki/befriended
Package befriended
Short Description Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.
License Apache-2.0
Homepage https://github.com/renoki-co/befriended
Informations about the package befriended
Laravel Befriended
Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models
🤝 Supporting
If you are using one or more Renoki Co. open-source packages in your production apps, in presentation demos, hobby projects, school projects or so, sponsor our work with Github Sponsors. 📦
🚀 Installation
Install the package:
Publish the config:
Publish the migrations:
🙌 Usage
The power of example is better here. This package allows you simply to assign followers, blockings or likes without too much effort. What makes the package powerful is that you can filter queries using scopes out-of-the-box.
Following
To follow other models, your model should use the CanFollow
trait and Follower
contract.
The other models that can be followed should use CanBeFollowed
trait and Followable
contract.
If your model can both follow & be followed, you can use Follow
trait and Following
contract.
Let's suppose we have an User
model which can follow and be followed. Within it, we can now check for followers or follow new users:
Now, let's suppose we have a Page
model, than can only be followed:
By default, if querying following()
and followers()
from the User
instance, the relationships will return only User
instances. If you plan to retrieve other instances, such as Page
, you can pass the model name or model class as an argument to the relationships:
On-demand, you can check if your model follows some other model:
Some users might want to remove followers from their list. The Followable
trait comes with a revokeFollower
method:
Note: Following, unfollowing or checking if following models that do not correctly implement CanBeFollowed
and Followable
will always return false
.
Filtering followed/unfollowed models
To filter followed or unfollowed models (which can be any other model) on query, your model which you will query should use the Rennokki\Befriended\Scopes\FollowFilterable
trait.
If your User
model can only like other Page
models, your Page
model should use the trait mentioned.
Blocking
Most of the functions are working like the follow feature, but this is helpful when your models would like to block other models.
Use CanBlock
trait and Blocker
contract to allow the model to block other models.
Adding CanBeBlocked
trait and Blockable
contract sets the model able to be blocked.
For both, you should be using Block
trait & Blocking
contract:
Most of the methods are the same:
Filtering blocked models
Blocking scopes provided takes away from the query the models that are blocked. Useful to stop showing content when your models blocks other models.
Make sure that the model that will be queried uses the Rennokki\Befriended\Scopes\BlockFilterable
trait.
Liking
Apply CanLike
trait and Liker
contract for models that can like:
CanBeLiked
and Likeable
trait can be used for models that can be liked:
Planning to use both, use the Like
trait and Liking
contact:
As you have already got started with, these are the methods:
Filtering liked content
Filtering liked content can make showing content easier. For example, showing in the news feed posts that weren't liked by an user can be helpful.
The model you're querying from must use the Rennokki\Befriended\Scopes\LikeFilterable
trait.
Let's suppose there are 10 pages in the database.
Follow requests
This is similar to the way Instagram allows you to request follow of a private profile.
To follow other models, your model should use the CanFollow
trait and Follower
contract.
The other models that can be followed should use CanBeFollowed
trait and Followable
contract.
If your model can both follow & be followed, you can use Follow
trait and Following
contract.
Let's suppose we have an User
model which can follow and be followed. Within it, we can now check for follower requests or request to follow a users:
Now, let's suppose we have a Page
model, than can only be followed:
You can then request or cancel the follow requests:
The one being followed can accept or decline the requests:
By default, if querying followRequests()
and followerRequests()
from the User
instance, the relationships will return only User
instances.
If you plan to retrieve other instances, such as Page
, you can pass the model name or model class as an argument to the relationships:
Note: Requesting, accepting, declining or checking if following models that do not correctly implement CanBeFollowed
and Followable
will always return false
.
🐛 Testing
🤝 Contributing
Please see CONTRIBUTING for details.
🔒 Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
🎉 Credits
- Alex Renoki
- All Contributors
All versions of befriended with dependencies
illuminate/database Version ^8.83|^9.0.1
illuminate/support Version ^8.83|^9.0.1