承接 ervinsvilumsons/laravel-eloquentql 相关项目开发

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

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

ervinsvilumsons/laravel-eloquentql

Composer 安装命令:

composer require ervinsvilumsons/laravel-eloquentql

包简介

Dynamically optimize Eloquent queries and API resources with JSON:API sparse fieldsets and includes.

README 文档

README

A small Laravel package to extend Eloquent models with JSON:API sparse fieldsets, include relation loading, and resource filtering.

Usage

  1. Add the trait to your Eloquent model:
use ErvinsVilumsons\LaravelEloquentQL\Concerns\HasEloquentQL;

class Post extends Model
{
    use HasEloquentQL;
}
  1. Use the jsonApi query scope with request input:
$posts = Post::query()
    ->jsonApi()
    ->get();
  1. Send JSON:API-style request parameters:
  • fields[posts]=title,body
  • include=author,comments

This will select only the requested post fields and eager load the requested relationships.

Resource filtering

You can filter resource output so only requested attributes and included relations are returned.

Standard Laravel resource example

use ErvinsVilumsons\LaravelEloquentQL\EloquentQL;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class PostResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        $resource = [
            'id' => $this->id,
            'title' => $this->title,
            'description' => $this->description,
            'author' => new AuthorResource($this->whenLoaded('author')),
        ];

        return EloquentQL::filterResource($resource, 'posts', $request);
    }
}

If the request uses fields[posts]=id,title and include=author, the response will only include id, title, and author.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固