PHP code example of hawaaworld / laravel-trends

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

    

hawaaworld / laravel-trends example snippets


use Hawaaworld\Trends\Contracts\Energy;
use Hawaaworld\Trends\Traits\HasEnergy;

class Hashtag extends Model implements Energy
{
    use HasEnergy;
    
    protected $appends = ['energy_amount'];
}

$hashtag->addEnergy(amount: 1.0);

$hashtag->energy->amount;

$trending = Trends::top(10);

/**
 * returns a collection type of the top 10 trending models:
 * 
 * Illuminate\Support\Collection {
 *   #items: array:10 [
 *     0 => App\Models\Article
 *     1 => App\Models\Article
 *     2 => App\Models\Video
 *     3 => App\Models\Article
 *     4 => App\Models\Hashtag
 *     5 => App\Models\Hashtag
 *     6 => App\Models\Article
 *     7 => App\Models\Video
 *     8 => App\Models\Comment
 *     9 => App\Models\Comment
 *   ]
 * }
 */

$trendingVideos = Trends::top(10, Video::class);

$trendingShortVideos = Trends::top(10, Video::class, function($query) {
    $query->where('duration', '<', 60);
});