PHP code example of kesty / laravel-reactions

1. Go to this page and download the library: Download kesty/laravel-reactions 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/ */

    

kesty / laravel-reactions example snippets


Kesty\LaravelReactions\Providers\ReactionsServiceProvider::class,

use Kesty\LaravelReactions\Traits\Reacts;

class User extends Model {
    use Reacts;
}

use Kesty\LaravelReactions\Traits\Reactable;
use Kesty\LaravelReactions\Contracts\ReactableInterface;

class Post extends Model implements ReactableInterface {
    use Reactable;
}

$likeReaction = Reaction::createFromName('like');
$likeReaction->save();

$loveReaction = Reaction::createFromName('love');
$loveReaction->save();

// picking the first user, for this example...
$user = User::first();

// the previously created reaction
$likeReaction = Reaction::where('name', '=', 'like')->first();

// picking up a post...
$awesomePost = Post::first();

// react to it!
$user->reactTo($awesomePost, $likeReaction);

// picking up a post...
$awesomePost = Post::first();

// get all reactions
$reactions = $awesomePost->reactions;

// picking up a post...
$awesomePost = Post::first();

// get a summary of related reactions
$reactionsSummary = $awesomePost->getReactionsSummary();

$reactionsSummary = $awesomePost->getReactionsSummary();
return $reactionsSummary;

// our awesome post.
$awesomePost = Post::first();

// every $reaction is a Reaction model
foreach($awesomePost->reactions as $reaction) 
{
    $user = $reaction->getResponder();
   
    // this will output "Francesco"
    echo $user->name;
}
bash
$ php artisan migrate