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.
36 lines
1.2 KiB
36 lines
1.2 KiB
<?php
|
|
|
|
namespace App\Forms;
|
|
|
|
use Spatie\Permission\Models\Permission;
|
|
use Kris\LaravelFormBuilder\Form;
|
|
use Kris\LaravelFormBuilder\Field;
|
|
|
|
class RoleForm extends Form
|
|
{
|
|
public function buildForm()
|
|
{
|
|
$this->add("name", Field::TEXT, ["label" => "名称", "rules" => "required"]);
|
|
$this->add("myindex", Field::NUMBER, ["label" => "排序值", "value" => "0"]);
|
|
$this->add('buttons', 'buttongroup', ["splitted" => true, "buttons" => [
|
|
["label" => "保存", "attr" => ["class" => "btn btn-primary mr-1", "type" => "submit"]],
|
|
["label" => "返回", "attr" => ["class" => "btn btn-light btn-back", "type" => "button"]]
|
|
]]);
|
|
}
|
|
|
|
public function getPermissionTree($guard = null)
|
|
{
|
|
$guard ?: $guard = config("auth.default.guard");
|
|
$routes = (new Permission())->where("guard_name", $guard)->get()->toArray();
|
|
$routes_tree = array2tree($routes, "id", "pid", 0);
|
|
$res = [];
|
|
foreach ($routes_tree as $route) {
|
|
$res[$route["id"]] = $route["name"];
|
|
foreach ($route["children"] as $child) {
|
|
$res[$child["id"]] = "|--" . $child["name"];
|
|
}
|
|
}
|
|
return $res;
|
|
}
|
|
}
|