You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.7 KiB

<?php
/**
* Created by PhpStorm.
* User: weizongsong
* Date: 2019-04-12
* Time: 22:34
*/
namespace App\Http\Controllers\Admin;
use App\Events\ManagerSaved;
use App\Forms\ManagerForm;
use App\Manager;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Kris\LaravelFormBuilder\FormBuilder;
class ManagerController extends CommonController
{
public $bladePath = "admin.manager";
public $urlPrefix = "admin/manager";
public $modelName = "管理老师";
public $modelClass = Manager::class;
public $formClass = ManagerForm::class;
public function index(Request $request)
{
$data = $this->model->with("projects")->paginate(10);
return view($this->bladePath . ".index", compact("data"));
}
public function edit($id = null, Request $request, FormBuilder $formBuilder)
{
$vo = $this->model->with("managerProjects")->find($id ?: $request->id);
$vo->project_id = $vo->managerProjects->pluck("project_id")->toArray();
$vo->password = "";
$form = $formBuilder->create($this->formClass, [
"method" => "POST",
"id" => "fm",
"url" => url($this->urlPrefix . "/update/" . $vo->id),
"class" => "form form-horizontal validate-form",
"model" => $vo
]);
$form->modify("password", "password", ["label" => "密码", "rules" => ""], true);
$form->add("_previous", "hidden", ["value" => (url()->previous())]);
return view($this->bladePath . ".create", compact("form"));
}
public function stored($model)
{
event(new ManagerSaved($model));
}
public function updated($model)
{
event(new ManagerSaved($model));
}
}