承接 nikolajlovenhardt/laravel-edgerank 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nikolajlovenhardt/laravel-edgerank

最新稳定版本:0.0.1

Composer 安装命令:

composer require nikolajlovenhardt/laravel-edgerank

包简介

Facebook Edgerank Algorithm for Laravel

README 文档

README

This package is a simple and flexible implementation of the Facebook EdgeRank algorithm for Laravel. Ideal for newsfeeds like Twitter, Facebook, LinkedIn, etc. Use the EdgeRank algorithm to sort posts and similar content based on factors such as likes, comments, shares, and time. The configuration makes it easy to manage the weighting of different parameters.

Installation and setup

Installation with Composer

composer require nikolajlovenhardt/laravel-edgerank

Publish resources

Config

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

Migrations

php artisan vendor:publish --tag="edgerank-migrations"

Use-cases and demos

Sort posts using default weights

use LaravelEdgeRank\Builders\EdgeRankBuilder;

$posts = EdgeRankBuilder::make()
    ->get();

Limits and offsets

Simple pagination

Paginate with a simple limit and offset

use LaravelEdgeRank\Builders\EdgeRankBuilder;

$posts = EdgeRankBuilder::make()
    ->limit(50)
    ->offset(100)
    ->get();

Cursor

Do you need to paginate using ids? No worries, we got your back

use LaravelEdgeRank\Builders\EdgeRankBuilder;

$posts = EdgeRankBuilder::make()
    ->after(100, 'id') // Get older posts than #100
    ->get();

Custom query

Use the $builder->query() method to access the query builder before fetching the results. This allows you to add custom query code still utilizing the EdgeRank-sort.

use LaravelEdgeRank\Builders\EdgeRankBuilder;
use App\Models\Feed\Item;

$friendIds = [1, 2, 3, 4];

$posts = EdgeRankBuilder::make(Item::class)
    ->query()
    ->where(function ($query) use ($friendIds) {
        $query->whereIn('user_id', $friendIds)
        
        $query->orWhereHas('user', function () {
            $query->where('is_public', '=', true)
        });
    })
    ->get();

Custom model / Override config

Use a custom model without configuration using the EdgeRankBuilder::make() method, and add custom config using weights()and options()-methods.

use LaravelEdgeRank\Builders\EdgeRankBuilder;
use App\Models\Feed\Item;

$posts = EdgeRankBuilder::make(Item::class)
    ->weights([
        'likes' => 10,
        'hates' => 2,
        'customRelation' => 1.5, // Item->customRelation(): HasMany
    ])
    ->get();

Contributing

Thank you for considering contributing to Laravel EdgeRank!

License

Laravel EdgeRank is open-sourced software licensed under the MIT license.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固