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/ */
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;
}
// 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();
// 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
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.