zhaiduting / column-relation
column-relation extension for laravel-admin
v4.0.1
2020-10-08 13:30 UTC
Requires
- php: >=7.0.0
- encore/laravel-admin: >1.999
This package is auto-updated.
Last update: 2026-06-05 15:26:36 UTC
README
安装
composer require zhaiduting/column-relation
注册扩展
在文件 app\Admin\bootstrap.php 中添加如下代码
// Add the following code to the file app\Admin\bootstrap.php
use Encore\Admin\Table\Column;
use Zhaiduting\ColumnRelation\Relate;
Column::extend('relate', Relate::class);
使用
在 laravel-admin 的控制器中,可以类似于下面这样使用 relate(..)
// e.g: use relate(..) in the app\Admin\Controllers\RoleController.php as follows
protected function table()
{
$table = new Table(new Role());
$table->column('id', __('Id'));
$table->column('name', '角色名称')
->relate('users', ['id', 'name'=> '用户'], function($user){
$user->name=
"<a target='_blank' href='". route('users.show', $user->id). "'>".
"<img class='img-thumbnail' width='30px' src='".
$user->avatar ."'> ".
$user->name.
"</a>";
});
$table->column('permissions', '权限')->pluck('name')->label('default');
return $table;
}
