Skip to content

Commit 0798adc

Browse files
committed
Initial Release
1 parent 6697215 commit 0798adc

21 files changed

+656
-0
lines changed

composer.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "codexshaper/laravel-permission",
3+
"description": "Laravel Multiple Authentication",
4+
"type": "library",
5+
"require": {},
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Md Abu Ahsan Basir",
10+
"email": "[email protected]"
11+
}
12+
],
13+
"minimum-stability": "dev",
14+
"autoload": {
15+
"psr-4": {
16+
"CodexShaper\\Permission\\": "src/"
17+
}
18+
},
19+
"extra": {
20+
"laravel": {
21+
"providers": [
22+
"CodexShaper\\Permission\\PermissionServiceProvider"
23+
],
24+
"aliases": {
25+
"PermissionFacade": "CodexShaper\\Permission\\Facades\\Permission",
26+
"Role": "CodexShaper\\Permission\\Models\\Role",
27+
"Permission": "CodexShaper\\Permission\\Models\\Permission",
28+
"HasRoles": "CodexShaper\\Permission\\Traits\\HasRoles",
29+
"HasPermissions": "CodexShaper\\Permission\\Traits\\HasPermissions"
30+
}
31+
}
32+
}
33+
}

config/permission.php

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
return [
3+
4+
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class CreateRolesTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('roles', function (Blueprint $table) {
17+
$table->increments('id');
18+
$table->string('name');
19+
$table->string('slug');
20+
$table->timestamps();
21+
});
22+
}
23+
24+
/**
25+
* Reverse the migrations.
26+
*
27+
* @return void
28+
*/
29+
public function down()
30+
{
31+
Schema::dropIfExists('roles');
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class CreateRoleUsersTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('role_users', function (Blueprint $table) {
17+
$table->increments('id');
18+
$table->integer('role_id');
19+
$table->integer('user_id');
20+
$table->timestamps();
21+
});
22+
}
23+
24+
/**
25+
* Reverse the migrations.
26+
*
27+
* @return void
28+
*/
29+
public function down()
30+
{
31+
Schema::dropIfExists('role_users');
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class CreatePermissionsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('permissions', function (Blueprint $table) {
17+
$table->increments('id');
18+
$table->string('name');
19+
$table->string('slug');
20+
$table->timestamps();
21+
});
22+
}
23+
24+
/**
25+
* Reverse the migrations.
26+
*
27+
* @return void
28+
*/
29+
public function down()
30+
{
31+
Schema::dropIfExists('permissions');
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class CreatePermissionRoleTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('permission_role', function (Blueprint $table) {
17+
$table->increments('id');
18+
$table->integer('permission_id');
19+
$table->integer('role_id');
20+
$table->timestamps();
21+
});
22+
}
23+
24+
/**
25+
* Reverse the migrations.
26+
*
27+
* @return void
28+
*/
29+
public function down()
30+
{
31+
Schema::dropIfExists('permission_role');
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
use Illuminate\Database\Seeder;
4+
5+
class PermissionDatabaseSeeder extends Seeder
6+
{
7+
protected $seedersPath = __DIR__.'/';
8+
9+
/**
10+
* Seed the application's database.
11+
*
12+
* @return void
13+
*/
14+
public function run()
15+
{
16+
$this->call(PermissionsSeeder::class);
17+
$this->call(RolesSeeder::class);
18+
$this->call(UsersSeeder::class);
19+
}
20+
}

database/seeds/PermissionsSeeder.php

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
use CodexShaper\Permission\Models\Permission;
4+
use Illuminate\Database\Seeder;
5+
6+
class PermissionsSeeder extends Seeder
7+
{
8+
/**
9+
* Run the database seeds.
10+
*
11+
* @return void
12+
*/
13+
public function run()
14+
{
15+
Permission::create([
16+
17+
'name' => 'Add Task',
18+
'slug' => str_slug('add task'),
19+
'created_at' => now(),
20+
'updated_at' => now(),
21+
]);
22+
23+
Permission::create([
24+
25+
'name' => 'Edit Task',
26+
'slug' => str_slug('edit task'),
27+
'created_at' => now(),
28+
'updated_at' => now(),
29+
]);
30+
31+
Permission::create([
32+
33+
'name' => 'Delete Task',
34+
'slug' => str_slug('delete task'),
35+
'created_at' => now(),
36+
'updated_at' => now(),
37+
]);
38+
}
39+
}

database/seeds/RolesSeeder.php

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
use CodexShaper\Permission\Models\Permission;
4+
use CodexShaper\Permission\Models\Role;
5+
use Illuminate\Database\Seeder;
6+
7+
class RolesSeeder extends Seeder
8+
{
9+
/**
10+
* Run the database seeds.
11+
*
12+
* @return void
13+
*/
14+
public function run()
15+
{
16+
$add = Permission::where('slug','add-task')->first();
17+
$edit = Permission::where('slug','edit-task')->first();
18+
$delete = Permission::where('slug','delete-task')->first();
19+
20+
$admin = Role::create([
21+
22+
'name' => 'Super Admin',
23+
'slug' => 'admin',
24+
'created_at' => now(),
25+
'updated_at' => now(),
26+
]);
27+
$admin->permissions()->attach([
28+
$add->id => [
29+
'created_at'=>now(),
30+
'updated_at'=>now()
31+
],
32+
$edit->id => [
33+
'created_at'=>now(),
34+
'updated_at'=>now()
35+
],
36+
$delete->id => [
37+
'created_at'=>now(),
38+
'updated_at'=>now()
39+
],
40+
]);
41+
42+
$manager = Role::create([
43+
44+
'name' => 'Manager',
45+
'slug' => 'manager',
46+
'created_at' => now(),
47+
'updated_at' => now(),
48+
]);
49+
$manager->permissions()->attach([
50+
$edit->id => [
51+
'created_at'=>now(),
52+
'updated_at'=>now()
53+
],
54+
]);
55+
56+
$writer = Role::create([
57+
58+
'name' => 'Writer',
59+
'slug' => 'writer',
60+
'created_at' => now(),
61+
'updated_at' => now(),
62+
]);
63+
64+
$client = Role::create([
65+
66+
'name' => 'Client',
67+
'slug' => 'client',
68+
'created_at' => now(),
69+
'updated_at' => now(),
70+
]);
71+
$client->permissions()->attach([
72+
$add->id => [
73+
'created_at'=>now(),
74+
'updated_at'=>now()
75+
],
76+
$edit->id => [
77+
'created_at'=>now(),
78+
'updated_at'=>now()
79+
],
80+
]);
81+
}
82+
}

database/seeds/UsersSeeder.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
use CodexShaper\Permission\Models\Role;
4+
use CodexShaper\Permission\Models\User;
5+
use Illuminate\Database\Seeder;
6+
7+
class UsersSeeder extends Seeder
8+
{
9+
/**
10+
* Run the database seeds.
11+
*
12+
* @return void
13+
*/
14+
public function run()
15+
{
16+
$admin_role = Role::where('slug','admin')->first();
17+
$user = new User;
18+
$user->name = "Admin";
19+
$user->email = "[email protected]";
20+
$user->password = Hash::make("123456");
21+
$user->save();
22+
$user->roles()->attach($admin_role,['created_at'=>now(),'updated_at'=>now()]);
23+
// $admin->role()->updateExistingPivot($admin_role, ['created_at'=>now(),'updated_at'=>now()]);
24+
}
25+
}

0 commit comments

Comments
 (0)