|
|
@@ -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();
|
|
|
+ }
|
|
|
+}
|