Usage

All methods available on this package to be used

This package offers any of the entities previously configured (check Getting started) the ability to save different type of interactions between them, by default but not only limited to you have the following interaction types:

  • Follow

  • Like

  • Subscribe

  • Participation

  • Bookmark

If you ever feel this is not enough you are completely free to send a PR to our repository or even better extend the enum and change it from the config file.

Save interactions

Knowing this you can simply use this package from the enum in the following way:

use OpenSoutheners\LaravelUserInteractions\Support\Facades\Interaction;
use OpenSoutheners\LaravelUserInteractions\UserInteractionType;

// User ID 1 will follow User ID 2
Interaction::from(User::find(1))
    ->to(User::find(2))
    ->does(UserInteractionType::Follow); // returns UserInteraction persisted model

Not a fan of Facades? You can use the functional way as well:

use OpenSoutheners\LaravelUserInteractions\UserInteractionType;

app('user.interaction')->from(User::find(1))
    ->to(User::find(2))
    ->does(UserInteractionType::Follow);

But you can do this in a even shorter way and without any import like this:

Possibilities are endless!

Toggle removal when interaction exists

If your interaction logic needs to toggle whenever the same type and entities are at the same direction you can use the following:

Checking existence of interaction

Now the previous code was for saving and you can check all the previously saved interactions using the following:

Or even shorter version:

And of course this is compatible with any other interaction (even those one you added into your own enum!).

But how about checking if a user has been followed by the other user, you can revert the causer/subject but we prepared a more semantic method for you:

Query interactions

You can save and check for interactions but what about querying? We got you covered:

Now is up to you to put all this in practice!

Last updated

Was this helpful?