Skip to content

Commit

Permalink
update the functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
subhobiswas committed Oct 7, 2024
1 parent 6f75fcc commit d863ce8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/Models/Permission.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php

namespace Lazycode\LaravelSimplePermission\Models;
namespace Lazycode\Permissions\Models;

use Illuminate\Database\Eloquent\Model;

class Permission extends Model
{
protected $fillable = ['name'];

public function roles()
{
return $this->belongsToMany(Role::class);
return $this->belongsToMany(Role::class, 'role_permission');
}
}
4 changes: 2 additions & 2 deletions src/Models/Role.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Lazycode\LaravelSimplePermission\Models;
namespace Lazycode\Permissions\Models;

use Illuminate\Database\Eloquent\Model;

Expand All @@ -10,6 +10,6 @@ class Role extends Model

public function permissions()
{
return $this->belongsToMany(Permission::class);
return $this->belongsToMany(Permission::class, 'role_permission');
}
}
File renamed without changes.
19 changes: 12 additions & 7 deletions src/database/migrations/create_permission_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ public function up()
});
}

if (!Schema::hasTable('users')) {
Schema::table('users', function (Blueprint $table) {
$table->foreignId('role_id')->nullable()->constrained('roles')->onDelete('set null');
});
if (Schema::hasTable('users')) {
if (!Schema::hasColumn('users', 'role_id')) {
Schema::table('users', function (Blueprint $table) {
$table->foreignId('role_id')->nullable()->constrained('roles')->onDelete('set null');
});
}
}

}
Expand All @@ -45,8 +47,11 @@ public function down()
Schema::dropIfExists('role_permission');
Schema::dropIfExists('permissions');
Schema::dropIfExists('roles');
Schema::table('users', function (Blueprint $table) {
$table->dropForeign(['role_id']);
});
if (Schema::hasTable('users') && Schema::hasColumn('users', 'role_id')) {
Schema::table('users', function (Blueprint $table) {
$table->dropForeign(['role_id']);
$table->dropColumn('role_id');
});
}
}
};

0 comments on commit d863ce8

Please sign in to comment.