File tree Expand file tree Collapse file tree 4 files changed +17
-12
lines changed Expand file tree Collapse file tree 4 files changed +17
-12
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
- namespace Lazycode \LaravelSimplePermission \Models ;
3
+ namespace Lazycode \Permissions \Models ;
4
4
5
5
use Illuminate \Database \Eloquent \Model ;
6
6
7
7
class Permission extends Model
8
8
{
9
9
protected $ fillable = ['name ' ];
10
-
10
+
11
11
public function roles ()
12
12
{
13
- return $ this ->belongsToMany (Role::class);
13
+ return $ this ->belongsToMany (Role::class, ' role_permission ' );
14
14
}
15
15
}
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
- namespace Lazycode \LaravelSimplePermission \Models ;
3
+ namespace Lazycode \Permissions \Models ;
4
4
5
5
use Illuminate \Database \Eloquent \Model ;
6
6
@@ -10,6 +10,6 @@ class Role extends Model
10
10
11
11
public function permissions ()
12
12
{
13
- return $ this ->belongsToMany (Permission::class);
13
+ return $ this ->belongsToMany (Permission::class, ' role_permission ' );
14
14
}
15
15
}
File renamed without changes.
Original file line number Diff line number Diff line change @@ -32,10 +32,12 @@ public function up()
32
32
});
33
33
}
34
34
35
- if (!Schema::hasTable ('users ' )) {
36
- Schema::table ('users ' , function (Blueprint $ table ) {
37
- $ table ->foreignId ('role_id ' )->nullable ()->constrained ('roles ' )->onDelete ('set null ' );
38
- });
35
+ if (Schema::hasTable ('users ' )) {
36
+ if (!Schema::hasColumn ('users ' , 'role_id ' )) {
37
+ Schema::table ('users ' , function (Blueprint $ table ) {
38
+ $ table ->foreignId ('role_id ' )->nullable ()->constrained ('roles ' )->onDelete ('set null ' );
39
+ });
40
+ }
39
41
}
40
42
41
43
}
@@ -45,8 +47,11 @@ public function down()
45
47
Schema::dropIfExists ('role_permission ' );
46
48
Schema::dropIfExists ('permissions ' );
47
49
Schema::dropIfExists ('roles ' );
48
- Schema::table ('users ' , function (Blueprint $ table ) {
49
- $ table ->dropForeign (['role_id ' ]);
50
- });
50
+ if (Schema::hasTable ('users ' ) && Schema::hasColumn ('users ' , 'role_id ' )) {
51
+ Schema::table ('users ' , function (Blueprint $ table ) {
52
+ $ table ->dropForeign (['role_id ' ]);
53
+ $ table ->dropColumn ('role_id ' );
54
+ });
55
+ }
51
56
}
52
57
};
You can’t perform that action at this time.
0 commit comments