tafadzwa/socialbeings

This is my package socialbeings

v1.0.0 2025-02-03 14:07 UTC

This package is auto-updated.

Last update: 2025-05-19 13:46:27 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A powerful and flexible package designed to streamline and enhance user engagement within your Laravel applications. This package provides seamless integration for features such as likes, favorites, subscriptions, and follows, allowing you to easily implement and manage user interactions.

Key Features

  • Likes: Enable users to express their appreciation for content.
  • Favorites: Allow users to save and revisit their preferred items.
  • Subscriptions: Keep users updated with the latest content through notifications.
  • Follows: Facilitate user connections and community building.

Elevate your application’s functionality and keep your users engaged with our comprehensive solution!

Installation

You can install the package via composer:

composer require tafadzwa/socialbeings

You can publish and run the migrations with:

php artisan vendor:publish --tag="socialbeings-migrations"
php artisan migrate

You can publish the config file with:s

php artisan vendor:publish --tag="socialbeings-config"

This is the contents of the published config file:

return [
    'use_uuids' => false, // Default to false, can be set to true by the user

    'user_table' => env('USER_TABLE', 'users'), // Default to 'users'
];

Following

You can follow any model by using import the CanFollow Trait which enable a trait to follow another model

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Likesocialjson\Likesocial\Traits\CanFollow;

class User extends Authenticatable
{
    use CanFollow;
    // Other model properties and methods...
}

Then the model you want to follow add the following trait

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Likesocialjson\Likesocial\Traits\Followable;

class Post extends Model
{
    use Followable;

    // Other model properties and methods...
}

Use Cases

    $user = User::find(1);
    $post = Post::find(1);

    $user->follow($post);
    $user->unfollow($post);
    $user->isFollowedBy($post);

    $post->followers(); //Retrieve all the followers
    $post->getFollowersCountAttribute();  // Count the number of followers
    $post->getFormattedFollowersCountAttribute();  // Formats using 10K if count is > 1000

Likes

You can like any model by using import the CanFollow Trait which enable a trait to follow another model

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Likesocialjson\Likesocial\Traits\CanLike;

class User extends Authenticatable
{
    use CanLike;
    // Other model properties and methods...
}

Then the model you want to follow add the following trait

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Likesocialjson\Likesocial\Traits\Likable;

class Post extends Model
{
    use Likable;

    // Other model properties and methods...
}

Use case

    $user = User::find(1);
    $post = Post::find(1);

    $user->like($post);
    $post->unlike($user->id);
    $post->isLikedBy($user->id)

Favourites

You can favour any model by using import the CanFavor Trait which enable a trait to follow another model

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Likesocialjson\Likesocial\Traits\CanFavor;

class User extends Authenticatable
{
    use CanFavor;
    // Other model properties and methods...
}

Then the model you want to favour add the following trait

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Likesocialjson\Likesocial\Traits\Favourable;

class Post extends Model
{
    use Favourable;

    // Other model properties and methods...
}

Use case

    $user = User::find(1);
    $post = Post::find(1);

    $user->favour($post);
    $post->unfavour($user->id);
    $post->isfavouredBy($user->id)

    $post->favorites;
    $post->favouriteers_count; // K format for > 1000 favourites

Subscriptions

You can favour any model by using import the CanFavor Trait which enable a trait to follow another model

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Likesocialjson\Likesocial\Traits\CanFavor;

class User extends Authenticatable
{
    use CanSubscribe;
    // Other model properties and methods...
}

Then the model you want to favour add the following trait

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Likesocialjson\Likesocial\Traits\Favourable;

class Post extends Model
{
    use Subscribable;

    // Other model properties and methods...
}

Use case

    $user = User::find(1);
    $post = Post::find(1);

    $user->subscribe($post);
    $post->unsubscribe($user->id);
    $post->isSubscribedBy($user->id)

    $post->subscriptions;
    $post->subscribers_count; // K format for > 1000 favourites

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.