Laravel-admin 这个后台很好用,几乎省去了html和js的困扰,让后台CURD变得优雅简洁。
这是一个自定义面的Demo
路由定义:
$router->get('mails/send', 'MailController@send');
$router->post('mails/send', 'MailController@send');
控制中写法:
public function send(Content $content)
{
//添加请求
if (request()->isMethod('post')) {
//验证
$data = request()->post();
$validate = Validator::make($data, [
'title' => 'required|max:125',
'content' => 'required'
]);
//处理
if ($validate->fails()) {
$content->withWarning('提醒', $validate);
} else {
Mail::create($data);
$content->withSuccess('提醒', '操作成功');
return redirect('/admin/mails');
}
}
$content->header('群发邮件');
$form = new \Encore\Admin\Widgets\Form();
$form->action('send');
$form->text('title','标题')->rules('required');
$form->textarea('content','内容')->rules('required');
$content->body($form);
$js = <<<SCRIPT
SCRIPT;
Admin::script($js);
return $content;
}