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.
84 lines
2.3 KiB
84 lines
2.3 KiB
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Admin;
|
|
use App\Forms\AdminForm;
|
|
use App\Models\Bed;
|
|
use App\Models\Orders;
|
|
use App\Models\Paramedic;
|
|
use App\Models\Project;
|
|
use Illuminate\Http\Request;
|
|
use Kris\LaravelFormBuilder\FormBuilder;
|
|
use Spatie\Permission\Models\Role;
|
|
|
|
class AdminController extends CommonController
|
|
{
|
|
public $urlPrefix = "admin/admin";
|
|
public $bladePath = "admin.admin";
|
|
public $modelClass = Admin::class;
|
|
public $formClass = AdminForm::class;
|
|
public $modelName = "用户";
|
|
|
|
public function index(Request $request)
|
|
{
|
|
$data = $this->model->paginate(20);
|
|
foreach ($data as $item) {
|
|
$item->projects = Project::whereIn("id", explode(",", $item->project_ids))->get();
|
|
}
|
|
|
|
$roles = (new Role())->where("guard_name", $this->guardName)->get();
|
|
return view($this->bladePath . ".index", compact("data", "roles"));
|
|
}
|
|
|
|
public function create(FormBuilder $formBuilder)
|
|
{
|
|
$form = $formBuilder->create($this->formClass, [
|
|
"method" => "POST",
|
|
"url" => url($this->urlPrefix . "/store")
|
|
]);
|
|
$form->modify("password", "password", ["rules" => "required"]);
|
|
|
|
return view($this->bladePath . ".create", compact("form"));
|
|
}
|
|
|
|
public function setRoles(Request $request)
|
|
{
|
|
$admin = Admin::find($request->id);
|
|
$roles = (new Role())->whereIn("id", (array)$request->role_id)->get();
|
|
|
|
try {
|
|
$admin->syncRoles((array)$request->role_id);
|
|
return $this->ajaxSuccess("授权成功");
|
|
} catch (\Exception $exception) {
|
|
return $this->ajaxError("授权失败:" . $exception->getMessage());
|
|
}
|
|
}
|
|
|
|
public function stored($model)
|
|
{
|
|
if (request()->project_id) {
|
|
$model->update([
|
|
"project_ids" => implode(",", request()->project_id)]);
|
|
} else {
|
|
$model->update([
|
|
"project_ids" => null
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function updated($model)
|
|
{
|
|
if (request()->project_id) {
|
|
$model->update([
|
|
"project_ids" => implode(",", request()->project_id)
|
|
]);
|
|
} else {
|
|
$model->update([
|
|
"project_ids" => null
|
|
]);
|
|
}
|
|
}
|
|
|
|
}
|