Просмотр исходного кода

修改 以停用货主在角色修改时能显示对应的货主权限

ajun 5 лет назад
Родитель
Сommit
f2addd3867
2 измененных файлов с 19 добавлено и 0 удалено
  1. 17 0
      app/Authority.php
  2. 2 0
      app/Http/Controllers/RoleController.php

+ 17 - 0
app/Authority.php

@@ -2,6 +2,7 @@
 
 namespace App;
 
+use Illuminate\Database\Eloquent\Collection;
 use Illuminate\Database\Eloquent\Model;
 use App\Traits\ModelTimeFormat;
 
@@ -32,4 +33,20 @@ class Authority extends Model
         }
         return '';
     }
+
+
+    public  static  function  filterRecycle(Collection $authorities)
+    {
+        $owners = Owner::query()->whereNotNull("deleted_at")->get();
+        $owner_names = $owners->map(function($owner){
+            if (mb_strpos($owner->name,"(停用)")){
+                $name =  mb_substr($owner->name,0,mb_stripos($owner->name,"(停用)"));
+                return "(货主:{$name})";
+            }
+            return "(货主:{$owner->name})";
+        })->toArray();
+        return $authorities->filter(function ($authority)use($owner_names){
+            return !in_array($authority->alias_name,$owner_names);
+        });
+    }
 }

+ 2 - 0
app/Http/Controllers/RoleController.php

@@ -44,6 +44,7 @@ class RoleController extends Controller
     {
         if(!Gate::allows('角色-录入')){ return redirect(url('/'));  }
         $authoritiesAll=Authority::orderBy('alias_name','desc')->get();
+        $authoritiesAll = Authority::filterRecycle($authoritiesAll);
         return view('maintenance.role.create',compact('authoritiesAll'));
     }
 
@@ -101,6 +102,7 @@ class RoleController extends Controller
     {
         if(!Gate::allows('角色-编辑')){ return redirect(url('/'));  }
         $authoritiesAll=Authority::orderBy('alias_name','desc')->get();
+        $authoritiesAll = Authority::filterRecycle($authoritiesAll);
         $authorities=$role->authorities()->get();
         return view('maintenance.role.edit',compact('role','authorities','authoritiesAll'));
     }