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

添加卸货 成本可见的权限

ajun 4 лет назад
Родитель
Сommit
b3b0c3e21d

+ 43 - 0
database/migrations/2021_06_18_093536_add__authority_discharge_task_authority.php

@@ -0,0 +1,43 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddAuthorityDischargeTaskAuthority extends Migration
+{
+
+    private $name = '人事管理-卸货-成本可见';
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        $authority = \App\Authority::query()->where('alias_name','卸货')->first();
+        $saveAuthority =  \App\Authority::query()->firstOrCreate(['alias_name' => $this->name],['name' => '卸货人事可见','parent_id' => $authority['id'] ?? '']);
+
+        $roles = \App\Role::query()->where('name','like','人事%')->get();
+        foreach ($roles as $role) {
+            $role->authorities()->attach($saveAuthority['id']);
+        }
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        $authority = \App\Authority::query()->where(['alias_name' => $this->name])->first();
+        if(!$authority) return ;
+
+        $roles = \App\Role::query()->where('name','like','人事%')->get();
+        foreach ($roles as $role) {
+            $role->detach($authority['id']);
+        }
+        $authority->delete();
+    }
+}