3 use Illuminate\Support\Facades\Schema;
4 use Illuminate\Database\Schema\Blueprint;
5 use Illuminate\Database\Migrations\Migration;
7 class CreateCommentsTable extends Migration
16 if (Schema::hasTable('comments')) {
19 Schema::create('comments', function (Blueprint $table) {
20 $table->increments('id')->unsigned();
21 $table->integer('page_id')->unsigned();
22 $table->longText('text')->nullable();
23 $table->longText('html')->nullable();
24 $table->integer('parent_id')->unsigned()->nullable();
25 $table->integer('created_by')->unsigned();
26 $table->integer('updated_by')->unsigned()->nullable();
27 $table->index(['page_id', 'parent_id']);
30 // Get roles with permissions we need to change
31 $adminRoleId = DB::table('roles')->where('system_name', '=', 'admin')->first()->id;
33 // Create & attach new entity permissions
34 $ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
36 foreach ($ops as $op) {
37 $permissionId = DB::table('role_permissions')->insertGetId([
38 'name' => strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op)),
39 'display_name' => $op . ' ' . $entity . 's',
40 'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
41 'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
43 DB::table('permission_role')->insert([
44 'role_id' => $adminRoleId,
45 'permission_id' => $permissionId
49 // Get roles with permissions we need to change
51 $editorRole = DB::table('roles')->where('name', '=', 'editor')->first();
52 if (!empty($editorRole)) {
53 $editorRoleId = $editorRole->id;
54 // Create & attach new entity permissions
55 $ops = ['Create All', 'Create Own', 'Update Own', 'Delete Own'];
57 foreach ($ops as $op) {
58 $permissionId = DB::table('role_permissions')->insertGetId([
59 'name' => strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op)),
60 'display_name' => $op . ' ' . $entity . 's',
61 'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
62 'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
64 DB::table('permission_role')->insert([
65 'role_id' => $editorRoleId,
66 'permission_id' => $permissionId
71 // Get roles with permissions we need to change
72 $viewerRole = DB::table('roles')->where('name', '=', 'viewer')->first();
73 if (!empty($viewerRole)) {
74 $viewerRoleId = $viewerRole->id;
75 // Create & attach new entity permissions
76 $ops = ['Create All'];
78 foreach ($ops as $op) {
79 $permissionId = DB::table('role_permissions')->insertGetId([
80 'name' => strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op)),
81 'display_name' => $op . ' ' . $entity . 's',
82 'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
83 'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
85 DB::table('permission_role')->insert([
86 'role_id' => $viewerRoleId,
87 'permission_id' => $permissionId
97 * Reverse the migrations.
101 public function down()
103 Schema::dropIfExists('comments');
104 // Create & attach new entity permissions
105 $ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
107 foreach ($ops as $op) {
108 $permName = strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op));
109 DB::table('role_permissions')->where('name', '=', $permName)->delete();