3 use Illuminate\Database\Migrations\Migration;
4 use Illuminate\Database\Schema\Blueprint;
5 use Illuminate\Support\Facades\Schema;
7 return new class extends Migration
16 Schema::create('comments', function (Blueprint $table) {
17 $table->increments('id')->unsigned();
18 $table->integer('entity_id')->unsigned();
19 $table->string('entity_type');
20 $table->longText('text')->nullable();
21 $table->longText('html')->nullable();
22 $table->integer('parent_id')->unsigned()->nullable();
23 $table->integer('local_id')->unsigned()->nullable();
24 $table->integer('created_by')->unsigned();
25 $table->integer('updated_by')->unsigned()->nullable();
28 $table->index(['entity_id', 'entity_type']);
29 $table->index(['local_id']);
31 // Assign new comment permissions to admin role
32 $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,
52 * Reverse the migrations.
56 public function down()
58 Schema::dropIfExists('comments');
59 // Delete comment role permissions
60 $ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
62 foreach ($ops as $op) {
63 $permName = strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op));
64 DB::table('role_permissions')->where('name', '=', $permName)->delete();