3 use Illuminate\Support\Facades\Schema;
4 use Illuminate\Database\Schema\Blueprint;
5 use Illuminate\Database\Migrations\Migration;
7 class CreateCommentsTable extends Migration
16 Schema::create('comments', function (Blueprint $table) {
17 $table->increments('id')->unsigned();
18 $table->integer('page_id')->unsigned();
19 $table->longText('text')->nullable();
20 $table->longText('html')->nullable();
21 $table->integer('parent_id')->unsigned()->nullable();
22 $table->integer('created_by')->unsigned();
23 $table->integer('updated_by')->unsigned()->nullable();
24 $table->boolean('active')->default(true);
26 $table->index(['page_id']);
29 // Assign new comment permissions to admin role
30 $adminRoleId = DB::table('roles')->where('system_name', '=', 'admin')->first()->id;
31 // Create & attach new entity permissions
32 $ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
34 foreach ($ops as $op) {
35 $permissionId = DB::table('role_permissions')->insertGetId([
36 'name' => strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op)),
37 'display_name' => $op . ' ' . $entity . 's',
38 'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
39 'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
41 DB::table('permission_role')->insert([
42 'role_id' => $adminRoleId,
43 'permission_id' => $permissionId
51 * Reverse the migrations.
55 public function down()
57 Schema::dropIfExists('comments');
58 // Delete comment role permissions
59 $ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
61 foreach ($ops as $op) {
62 $permName = strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op));
63 DB::table('role_permissions')->where('name', '=', $permName)->delete();