PHP code example of toneflix-code / social-interactions

1. Go to this page and download the library: Download toneflix-code/social-interactions library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

toneflix-code / social-interactions example snippets


ToneflixCode\SocialInteractions\SocialInteractionsServiceProvider::class

'SocialInteraction' => ToneflixCode\SocialInteractions\Facades\SocialInteraction::class

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use ToneflixCode\SocialInteractions\Traits\CanSocialInteract;

class User extends Authenticatable
{
    use HasFactory;
    use CanSocialInteract;
}

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use ToneflixCode\SocialInteractions\Traits\HasSocialInteractions;

class Post extends Model
{
    use HasFactory;
    use HasSocialInteractions;
}

    $user = \App\Models\User::find(1);
    $post = \App\Models\Post::find(2);

    $reaction = $user->leaveReaction($post, true);
    

    $user = \App\Models\User::find(1);
    $post = \App\Models\Post::find(2);

    $reaction = $user->leaveReaction($post, false);
    

$user = \App\Models\User::find(1);
$post = \App\Models\Post::find(2);

$liked = $post->isLiked($user);

$user = \App\Models\User::find(1);
$post = \App\Models\Post::find(2);

$reaction = $user->leaveReaction($post, 'dislike');

$user = \App\Models\User::find(1);
$post = \App\Models\Post::find(2);

$disliked = $post->isDisliked($user);

$user = \App\Models\User::find(1);
$post = \App\Models\Post::find(2);

$reaction = $user->leaveReaction($post, 'love');

$user = \App\Models\User::find(3);
$post = \App\Models\Post::find(2);

$reaction = $user->leaveReaction($post, 'haha');

$user = \App\Models\User::find(1);
$post = \App\Models\Post::find(2);

$reacted = $post->isReacted($user);

    $user = \App\Models\User::find(1);
    $post = \App\Models\Post::find(2);

    $reaction = $post->giveVote($user, true);
    

    $user = \App\Models\User::find(1);
    $post = \App\Models\Post::find(2);

    $reaction = $post->giveVote($user, false);
    

$user = \App\Models\User::find(1);
$post = \App\Models\Post::find(2);

$voted = $post->isVoted($user);

    $user = \App\Models\User::find(1);
    $post = \App\Models\Post::find(2);

    $reaction = $post->toggleSave($user, true);
    

    $user = \App\Models\User::find(1);
    $post = \App\Models\Post::find(2);

    $reaction = $post->toggleSave($user, false);
    

$user = \App\Models\User::find(1);
$post = \App\Models\Post::find(2);

$saved = $post->isSaved($user);

$user = \App\Models\User::find(1);
$post = \App\Models\Post::find(2);

$saved = $post->isSaved($user, 'default');

    $user = \App\Models\User::find(1);
    $post = \App\Models\Post::find(2);

    $reaction = $post->toggleSaveToList($user, true, 'default');
    $reaction = $post->toggleSaveToList($user, true, 'reusable');
    

    $user = \App\Models\User::find(1);
    $post = \App\Models\Post::find(2);

    $reaction = $post->toggleSaveToList($user, false, 'default');
    $reaction = $post->toggleSaveToList($user, false, 'reusable');
    

$user = \App\Models\User::find(1);

$lists = $user->saved_social_lists;

$user = \App\Models\User::find(1);

$lists = $user->deleteSavedSocialList('default');

$user = \App\Models\User::find(1);

$lists = $user->deleteSavedSocialList(true);

$post = \App\Models\Post::find(1);

$interactions = $post->socialInteractions;

$post = \App\Models\Post::find(1);

$interactions = $post->socialInteractions()->orderBy('id')->paginate(10);

$post = \App\Models\Post::find(1);

$interactions = $post->socialInteractions;

foreach ($interactions as $interaction) {
    $interactor = $interaction->interactor;
}

$post = \App\Models\Post::find(1);

$interactions = $post->socialInteracts;

$post = \App\Models\Post::find(1);

$interactions = $post->socialInteracts()->orderBy('id')->paginate(10);

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

$interaction = $post->modelInteraction($user);

$post = \App\Models\Post::find(1);

$data = $post->socialInteractionData();

Array[
    'votes' => 10,
    'likes' => 5,
    'dislikes' => 1,
    'reactions' => 7,
]

$post = \App\Models\Post::find(1);
$user = \App\Models\User::find(3);

$data = $post->socialInteractionData($user);

Array[
    'votes' => 10,
    'likes' => 5,
    'dislikes' => 1,
    'reactions' => 7,
    'saved' => true,
    'voted' => true,
    'liked' => false,
    'reacted' => true,
    'ownvotes' => 1,
    'disliked' => false,
    'reaction' => 'love',
    'reaction_color' => 'red',
    'state_icons' => [
        'saved' => 'fas fa-bookmark',
        'voted' => 'fas fa-thumbs-up',
        'disliked' => 'far fa-thumbs-down',
        'reaction' => 'fas fa-heart',
    ],
]

$post = \App\Models\Post::find(1);

$saves = $post->socialInteractionSaves;

$post = \App\Models\Post::find(1);

$saves = $post->socialInteractionSaves()->whereBetween('created_at', ['2024-00-12 11:22:01', '2024-07-12 11:22:01'])->paginate(10);

$post = \App\Models\Post::find(1);

$saves = $post->savedSocialInteracts;

$post = \App\Models\Post::find(1);

$saves = $post->savedSocialInteracts()->whereBetween('created_at', ['2024-00-12 11:22:01', '2024-07-12 11:22:01'])->paginate(10);
shell
        php artisan vendor:publish --tag=social-interactions-config
        
shell
        php artisan vendor:publish --tag=social-interactions-migrations
        
shell
    php artisan migrate