christhompsontldr/laraman
Composer 安装命令:
composer create-project christhompsontldr/laraman
包简介
Laravel crud manager.
README 文档
README
Laraman is a Laravel based administration panel.
Laraman provides a quick user interface for reviewing and managing data stored in your database.
Laraman is really good at the index route, searching, filtering and pagination. It leaves the create, update and delete to the application.
Installation
Composer
Require this package with composer:
composer require christhompsontldr/laraman
Service Provider
After updating composer, add the ServiceProvider to the providers array in config/app.php
Laravel 5.x:
Christhompsontldr\Laraman\ServiceProvider::class,
Config
Copy the config/laraman.php file from the packge to your applications config directory.
Routes
Laraman utilizes the resource method in routes to build all the required routes.
In routes/web.php add"
Laraman::resource('users');
Laraman will now look for a app/Http/Controllers/Manage/UserController.php.
The namespace of the Laraman controllers can be changed in the config/laraman.php file. Manage is the default namespace.
Models
Include the Laraman trait on your model
use Christhompsontldr\Laraman\Traits\LaramanModel;
and then use it
use LaramanModel;
Laraman utilizes something we call formatters. We have included a few default formatters, but you are welcome to write your own. Review the Christhompsontldr\Laraman\Traits\LaramanModel class for examples.
Think of these as post-accessors. This allows Laraman to manipulate model data after the application's accessors have been applied.
Example of using the date formatter
public function __configure()
{
$this->columns = [
[
'field' => 'created_at',
'display' => 'Created',
'formatter' => 'datetime',
'options' => [
'format' => 'F j, Y g:ia',
]
],
Controllers
Include the Laraman trait on your controller
use Christhompsontldr\Laraman\Traits\LaramanController;
and then use it
use LaramanController;
Laraman expects your controller to have a __configure() method where a few things are configured.
public function __configure()
{
$this->columns = [
[
'field' => 'id',
],
[
'field' => 'name',
],
[
'field' => 'email',
],
[
'field' => 'organization.name',
'display' => 'Organization',
],
];
$this->buttons = [
config('laraman.view.hintpath') . '::buttons.view',
];
}
This example will build an index route with a table with 4 columns and 1 button.
Options
Model
If the model name you want to use doesn't make the naming convention you used for your controller, it can be set with the model attribute
public function __configure()
{
$this->model = \App\Mail::class;
Views
Need to load views from another path, use the viewPath attribute
public function __configure()
{
$this->viewPath = config('laraman.view.hintpath') . '::mail';
Route
The route where laraman lives for this controller can be changed
public function __configure()
{
$this->routePath = config('laraman.route.prefix') . '.mail';
Search
You can enable model level searches with the searchEnabled attribute
public function __configure()
{
$this->searchEnabled = true;
Your model will need to have implemented a search() method. This is commonly found in the Laravel Scout library or the Algolia Search for Laravel library.
Columns
The only required array key for a column is the field. This will be the database column name you want to display.
display
display will change the name displayed to the user in the top of the table.
related model data
The dot notation can be used to reach related model data.
public function __configure()
{
$this->columns = [
[
'field' => 'id',
],
[
'field' => 'name',
],
[
'field' => 'email',
],
[
'field' => 'organization.name',
'display' => 'Organization',
],
];
organization.name will load the name from the related organization.
blade
If you need to use a custom blade for a field, define it like this
public function __configure()
{
$this->columns = [
[
'field' => 'braintree_customer_id',
'display' => 'Braintree Customer',
'options' => [
'blade' => config('laraman.view.hintpath') . '::fields.memberships.customer'
]
],
Filters
Laraman can utilize filters defined on the model
public function __configure()
{
$this->filters = [
[
'field' => 'event',
'display' => 'Event',
'type' => 'select',
'values' => [
'send' => 'send',
'hard_bounce' => 'hard bounce',
'open' => 'open',
'soft_bounce' => 'soft bounce',
'deferral' => 'clickdeferral',
'delivered' => 'delivered',
'reject' => 'reject',
'spam' => 'spam',
]
],
];
If the model has a filterEvent defined, it will be utilized
public function filterEvent($builder, $val)
{
return $builder->{$val}();
}
Could be used to apply model scopes like scopeSend() and scopeOpen().
Buttons
Action buttons can be added with the buttons attribute
public function __configure()
{
$this->buttons = [
'laraman::buttons.braintree-transaction',
'laraman::buttons.receipt',
];
Scopes
If you need to scope the model being used, define a scope method in your controller
class TrialController extends Controller
{
use LaramanController;
public function scope($builder)
{
// only show trials
return $builder->trial();
}
Extras
Have extra data to pass from the controller to the view, use extras
class TrialController extends Controller
{
use LaramanController;
public function __configure()
{
$this->columns = [
[
'field' => 'created_at',
'display' => 'Created',
'formatter' => 'datetime',
'options' => [
'format' => 'F j, Y g:ia',
]
]
];
// active trials
$this->extras['active'] = Membership::trial()->active()->count();
// by day
$this->extras['byday'] = [];
foreach (range(0, 30) as $day) {
$date = Carbon::now()->subDays($day)->format('Y-m-d');
$this->extras['byday'][$date] = Membership::trial()->active()->whereDate('created_at', $date)->count();
}
}
christhompsontldr/laraman 适用场景与选型建议
christhompsontldr/laraman 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.2k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2017 年 05 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「admin」 「manager」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 christhompsontldr/laraman 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 christhompsontldr/laraman 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 christhompsontldr/laraman 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
2lenet/EasyAdminPlusBundle
Analysis module for finding problematical shop data.
KCFinder web file manager
Publish / Subscribe / Event Manager
AclManager plugin for CakePHP 3.x
统计信息
- 总下载量: 1.2k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-05-02