gocrew / laravel-presenter
该包已废弃,不再维护。未建议替代包。
查看 Laravel 的 Presenters。
1.0.1
2015-11-20 00:07 UTC
Requires
- php: >=5.5.0
- illuminate/console: ~5
- illuminate/support: ~5
Requires (Dev)
- mockery/mockery: ~0.9
- phpspec/phpspec: ~2.0
This package is not auto-updated.
Last update: 2017-01-20 22:57:33 UTC
README
安装
将 Presenter 添加到 composer.json 文件中
"require": { "gocrew/laravel-presenter": "~1.0" }
现在,从项目的根目录运行 composer update 命令
composer update
注册包
在 app/config/app.php
中包含服务提供者。服务提供者对于 generator artisan 命令是必需的。
'providers' => [ ... gocrew\LaravelPresenter\PresenterServiceProvider::class ... ];
使用方法
首先,生成一个 presenter
php artisan make:presenter [presenter name]
这是一个 presenter 的示例。
use gocrew\LaravelPresenter\Presenter; class UserPresenter extends Presenter { public function name() { return ucfirst($this->first_name) . ' ' . ucfirst($this->last_name); } public function joined() { return $this->created_at->diffForHumans(); } }
然后,在你的实体中引入 gocrew\LaravelPresenter\Presentable 特性,这将自动为您实例化 presenter 类。
use gocrew\LaravelPresenter\Presentable; class User extends Eloquent { use Presentable; protected $presenter = App\UserPresenter::class; }
这就完成了。现在您可以执行以下操作
<p>Hi, {{ $user->present()->name }}</p>
许可证
本仓库内容遵循 MIT 许可。