Laravel Acquaintances

repository·master·Indexed 21 days ago

https://github.com/multicaret/laravel-acquaintances

A modular package for adding social features to Eloquent models, including Friendships, Verifications, and Interactions (Follow, Like, Favorite, Report, Subscribe, Vote, View). It provides a multi-type rating system and supports relationship categorization via groups. Compatible with PHP 8.1+ and Laravel 9 through 13.

Tokens
13K
Snippets
53
Records
69
Agent score
73%

What's inside laravel-acquaintances

  1. Overview of Laravel Acquaintances capabilities

    master

    Laravel Acquaintances is a lightweight package designed to add social capabilities to Eloquent models without requiring a monolithic framework dependency. It provides the following core features:

    • Friendships: Manage connections between models using groups.
    • Verifications: Implement peer attestations using groups.
    • Interactions: Support for Follow, Like, Favorite, Report, Subscribe, Vote, and View actions.
    • Ratings: An advanced, multi-type rating system.

    It is built to be modular and works with various Illuminate components.

  2. Maintain event dispatching when modifying core flows

    master
    The package dispatches specific events during its core operations. When customizing or modifying core application flows, ensure you continue to dispatch the events listed in the package documentation (docs/events.md) to maintain expected behavior and compatibility with other listeners.
  3. Run Acquaintances migrations

    master

    After installing the package and (optionally) publishing the migrations, run the standard Laravel migration command to create the necessary database tables:

    Note: By default, acquaintances.migrations is set to false in the configuration to prevent auto-loading vendor migrations. If you have not published the migrations manually, you may need to check the configuration or follow the specific migration loading documentation.

    php artisan migrate
  4. Publish acquaintances migrations

    master

    To manually manage the package migrations within your application's database/migrations folder, use the vendor:publish command with the acquaintances-migrations tag. This process uses updateMigrationDate() to ensure the files are created with current timestamps, allowing them to run in the correct order relative to your existing migrations.

    php artisan vendor:publish --tag=acquaintances-migrations
  5. Add Acquaintances traits to your models

    master

    To enable social features, import and use the relevant traits in your Eloquent models.

    Common traits include:

    • Friendable, Verifiable for relationship management.
    • CanFollow, CanBeFollowed for following logic.
    • CanLike, CanBeLiked for likes.
    • CanRate, CanBeRated for ratings.
    use Multicaret\Acquaintances\Traits\Friendable;
    use Multicaret\Acquaintances\Traits\Verifiable;
    use Multicaret\Acquaintances\Traits\CanFollow;
    use Multicaret\Acquaintances\Traits\CanBeFollowed;
    use Multicaret\Acquaintances\Traits\CanLike;
    use Multicaret\Acquaintances\Traits\CanBeLiked;
    use Multicaret\Acquaintances\Traits\CanRate;
    use Multicaret\Acquaintances\Traits\CanBeRated;
    
    class User extends Model {
        use Friendable, Verifiable;
        use CanFollow, CanBeFollowed;
        use CanLike, CanBeLiked;
        use CanRate, CanBeRated;
    }
  6. Synchronize table names when changing acquaintances configuration

    master
    If you modify the table names in your configuration using config('acquaintances.tables.*'), you must ensure that both your published migrations and your runtime configuration are kept in sync. Failure to do so will result in mismatches between the database schema and the application's expectations.
  7. Enable interactions on User and Target models

    master

    To enable social interactions (like following, liking, etc.), you must add specific traits to both the acting user model and the target models (e.g., a Post or User being followed).

    Acting User Traits:

    • Multicaret\Acquaintances\Traits\CanFollow
    • Multicaret\Acquaintances\Traits\CanLike
    • Multicaret\Acquaintances\Traits\CanFavorite
    • Multicaret\Acquaintances\Traits\CanSubscribe
    • Multicaret\Acquaintances\Traits\CanVote
    • Multicaret\Acquaintances\Traits\CanReport

    Target Model Traits:

    • Multicaret\Acquaintances\Traits\CanBeFollowed
    • Multicaret\Acquaintances\Traits\CanBeLiked
    • Multicaret\Acquaintances\Traits\CanBeFavorited
    • Multicaret\Acquaintances\Traits\CanBeVoted
    • Multicaret\Acquaintances\Traits\CanBeRated
    • Multicaret\Acquaintances\Traits\CanBeReported
    • Multicaret\Acquaintances\Traits\CanBeViewed
    use Multicaret\Acquaintances\Traits\CanFollow;
    use Multicaret\Acquaintances\Traits\CanLike;
    // ... other traits
    
    class User extends Model {
      use CanFollow, CanLike, CanFavorite, CanSubscribe, CanVote, CanReport;
    }
    
    class Post extends Model {
      use CanBeFollowed, CanBeLiked, CanBeFavorited, CanBeVoted, CanBeRated, CanBeReported, CanBeViewed;
    }