<?php
namespace App\Admin\Controllers;
use App\Facades\CommonFacade;
use App\User;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;
class ManageUserController extends Controller
{
use HasResourceActions;
public function index(Content $content)
{
return $content
->header('用户')
->description('列表')
->body($this->grid());
}
public function show($id, Content $content)
{
return $content
->header('用户')
->description('详情')
->body($this->detail($id));
}
public function edit($id, Content $content)
{
return $content
->header('编辑')
->description('用户')
->body($this->form()->edit($id));
}
public function create(Content $content)
{
return $content
->header('创建')
->description('用户')
->body($this->form());
}
protected function grid()
{
$grid = new Grid(new User);
$grid->disableCreateButton();
$grid->model()->whereHas('roles', function($query) {
$query->where('slug', 'Personal');
});
$grid->username('用户名');
$grid->name('姓名');
$grid->service_user()->name('专属客服')->label();
$grid->avatar('头像')->image('', 50,50);;
return $grid;
}
protected function detail($id)
{
$show = new Show(User::findOrFail($id));
$show->username('Username');
$show->password('Password');
$show->name('Name');
$show->avatar('Avatar');
$show->remember_token('Remember token');
$show->created_at('Created at');
$show->updated_at('Updated at');
$show->sex('Sex');
$show->mail('Mail');
$show->phone('Phone');
$show->type('Type');
$show->idNo('IdNo');
$show->jobNo('JobNo');
return $show;
}
protected function form()
{
$form = new Form(new User);
$form->text('username', '用户名');
$form->text('name', '姓名');
$options = CommonFacade::getServiceUserOptions();
$form->select('service_user_id', '专属客服')->options($options);
return $form;
}
}