Download the PHP package developer-savyour/befriended without Composer
On this page you can find all versions of the php package developer-savyour/befriended. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download developer-savyour/befriended
More information about developer-savyour/befriended
Files in developer-savyour/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 MIT
Homepage https://github.com/rennokki/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. Laravel Befriended comes with scopes that manage filtering content that gives you easy control better what your user can see and cannot see.
Switching from 1.1.x to 1.2.x
The main difference is that the traits that are responsible for filtering content got a better eloquent capability.
Make sure you replace the following traits:
Rennokki\Befriended\Scopes\CanFilterFollowingModels
Rennokki\Befriended\Scopes\CanFilterUnfollowedModels
Rennokki\Befriended\Scopes\CanFilterBlockedModels
Rennokki\Befriended\Scopes\CanFilterUnlikedModels
with the following ones that are paired by the action they filter:
Rennokki\Befriended\Scopes\FollowFilterable
Rennokki\Befriended\Scopes\BlockFilterable
Rennokki\Befriended\Scopes\LikeFilterable
Installation
Install the package:
If your Laravel version does not support package discovery, add this line in the providers
array in your config/app.php
file:
Publish the config file & migration files:
Migrate the database:
Example
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:
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.