3 use Illuminate\Database\Migrations\Migration;
4 use Illuminate\Database\Schema\Blueprint;
5 use Illuminate\Support\Facades\Schema;
7 class CreateAttachmentsTable extends Migration
16 Schema::create('attachments', function (Blueprint $table) {
17 $table->increments('id');
18 $table->string('name');
19 $table->string('path');
20 $table->string('extension', 20);
21 $table->integer('uploaded_to');
23 $table->boolean('external');
24 $table->integer('order');
26 $table->integer('created_by');
27 $table->integer('updated_by');
29 $table->index('uploaded_to');
33 // Get roles with permissions we need to change
34 $adminRoleId = DB::table('roles')->where('system_name', '=', 'admin')->first()->id;
36 // Create & attach new entity permissions
37 $ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
38 $entity = 'Attachment';
39 foreach ($ops as $op) {
40 $permissionId = DB::table('role_permissions')->insertGetId([
41 'name' => strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op)),
42 'display_name' => $op . ' ' . $entity . 's',
43 'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
44 'updated_at' => \Carbon\Carbon::now()->toDateTimeString(),
46 DB::table('permission_role')->insert([
47 'role_id' => $adminRoleId,
48 'permission_id' => $permissionId,
54 * Reverse the migrations.
58 public function down()
60 Schema::dropIfExists('attachments');
62 // Create & attach new entity permissions
63 $ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
64 $entity = 'Attachment';
65 foreach ($ops as $op) {
66 $permName = strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op));
67 DB::table('role_permissions')->where('name', '=', $permName)->delete();