taylornetwork/presenter
Composer 安装命令:
composer require taylornetwork/presenter
包简介
A presenter class for Laravel.
README 文档
README
Adds another place to put logic for models. Instead of cluttering up models with logic to display/format data, add them to a presenter!
This is a rewrite of laracasts/Presenter with some added functionality, commands, etc.
Install
Via Composer
$ composer require taylornetwork/presenter
Setup
Add the service provider to the providers array in config/app.php
'providers' => [ TaylorNetwork\Presenter\PresenterServiceProvider::class, ],
Publish Config
$ php artisan vendor:publish
This will add config/presenter.php where you can define the namespace you want your presenter classes to be stored.
Usage
Create a presenter using the artisan command, for example a presenter for the User model.
$ php artisan make:presenter UserPresenter
This will create a presenter class you can add logic to that you don't want in the model or the view. Model attributes are accessible via $this->model
use TaylorNetwork\Presenter\Presenter; class UserPresenter extends Presenter { /** * Get the user's full name * * @return string */ public function fullName() { return $this->model->first_name . ' ' . $this->model->last_name; } /** * Get the time since the user signed up * * @return string */ public function userSince() { return $this->model->created_at->diffForHumans(); } }
You will need to add the presentable trait and a $presenter property to your model
use TaylorNetwork\Presenter\Presentable; use App\Presenters\UserPresenter; class User extends Model { use Presentable; /** * Presenter Class * * @var string */ protected $presenter = UserPresenter::class; // Code }
You can access the presenter with present()
<h1>{{ $user->present()->fullName }}, you signed up {{ $user->present()->userSince }}</h1>
Credits
- Main Author: Sam Taylor
License
The MIT License (MIT). Please see License File for more information.
taylornetwork/presenter 适用场景与选型建议
taylornetwork/presenter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 11 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 taylornetwork/presenter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 taylornetwork/presenter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 20
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2016-11-16