gathercontent/laravel-fractal 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

gathercontent/laravel-fractal

最新稳定版本:1.0.1

Composer 安装命令:

composer require gathercontent/laravel-fractal

包简介

A Laravel Service Provider for Fractal

README 文档

README

A Laravel Service Provider for League/Fractal.

Installation

Add laravel-fractal to your composer.json file:

"require": { "gathercontent/laravel-fractal": "~1.0" }

Get composer to install the package:

$ composer require gathercontent/laravel-fractal 

Registering the Package

Register the service provider within the providers array found in app/config/app.php:

'providers' => array( // ... GatherContent\LaravelFractal\LaravelFractalServiceProvider::class )

Add an alias within the aliases array found in app/config/app.php:

'aliases' => array( // ... 'Fractal' => GatherContent\LaravelFractal\LaravelFractalFacade::class, )

Configuration

To override the default configuration, you can publish the config files to your application. Artisan can do this automatically for you via the command line:

$ php artisan vendor:publish

Usage

Basic Example

Formatting a single item:

// routes.php Route::get('/me', array('before' => 'auth', function () { return Fractal::item(Auth::user(), new UserTransformer); }));

Formatting a collection:

// routes.php Route::get('/comments', function () { return Fractal::collection(Comment::all(), new CommentTransformer); });

Adding meta data:

// routes.php Route::get('/comments', function () { return Fractal::collection(Comment::all(), new CommentTransformer, function ($resources) { $resources->setMetaValue('foo', 'bar'); }); });

Returning a paginated collection:

// routes.php Route::get('/comments', function () { return Fractal::collection(Comment::paginate(), new CommentTransformer); });

Using a custom pagination adapter:

// routes.php Route::get('/comments', function () { $comments = Comment::paginate(); $adapter = new MyIlluminatePaginationAdapter($comments); return Fractal::collection($comments, new CommentTransformer, null, $adapter); });

统计信息

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

GitHub 信息

  • Stars: 50
  • Watchers: 9
  • Forks: 11
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固