Skip to content

Commit 00c27a7

Browse files
committed
commit regrading the first push for testing installation process
1 parent f002bf4 commit 00c27a7

File tree

5 files changed

+129
-0
lines changed

5 files changed

+129
-0
lines changed

composer.json

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "lazycode/laravel-simple-permissions",
3+
"description": "A Laravel package for handling roles and permissions.",
4+
"keywords": [
5+
"laravel",
6+
"permission",
7+
"permissions",
8+
"roles",
9+
"security"
10+
],
11+
"require": {
12+
"php": ">=7.4",
13+
"illuminate/support": "^9.0",
14+
"illuminate/database": "^9.0",
15+
"illuminate/auth": "^9.0"
16+
},
17+
"license": "MIT",
18+
"autoload": {
19+
"psr-4": {
20+
"Lazycode\\Permissions \\": "src/"
21+
}
22+
},
23+
"authors": [
24+
{
25+
"name": "Subho Biswas",
26+
"email": "[email protected]",
27+
"homepage": "https://github.com/subhobiswas"
28+
}
29+
],
30+
"minimum-stability": "dev",
31+
"prefer-stable": true,
32+
"scripts": {
33+
"test": "phpunit",
34+
"format": "php-cs-fixer fix --allow-risky=yes",
35+
"analyse": "phpstan analyse"
36+
}
37+
}

src/Models/Permission.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Lazycode\LaravelSimplePermission\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class Permission extends Model
8+
{
9+
protected $guarded = [];
10+
11+
public function roles()
12+
{
13+
return $this->belongsToMany(Role::class);
14+
}
15+
}

src/Models/Role.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Lazycode\LaravelSimplePermission\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class Role extends Model
8+
{
9+
protected $guarded = [];
10+
11+
public function permissions()
12+
{
13+
return $this->belongsToMany(Permission::class);
14+
}
15+
}

src/PermissionServiceProvider.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Lazycode\LaravelSimplePermission;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
7+
class PermissionServiceProvider extends ServiceProvider
8+
{
9+
public function boot()
10+
{
11+
// Publish the configuration and migration files
12+
$this->publishes([
13+
__DIR__ . '/../config/permission.php' => config_path('permission.php'),
14+
__DIR__ . '/../database/migrations/create_permission_tables.php.stub' => database_path('migrations/' . date('Y_m_d_His', time()) . '_create_permission_tables.php'),
15+
], 'config');
16+
17+
// Load migrations
18+
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
19+
}
20+
21+
public function register()
22+
{
23+
// Merge configuration
24+
$this->mergeConfigFrom(__DIR__ . '/../config/permission.php', 'permission');
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class CreatePermissionTables extends Migration
8+
{
9+
public function up()
10+
{
11+
Schema::create('roles', function (Blueprint $table) {
12+
$table->id();
13+
$table->string('name');
14+
$table->timestamps();
15+
});
16+
17+
Schema::create('permissions', function (Blueprint $table) {
18+
$table->id();
19+
$table->string('name');
20+
$table->timestamps();
21+
});
22+
23+
Schema::create('role_permission', function (Blueprint $table) {
24+
$table->id();
25+
$table->foreignId('role_id')->constrained()->onDelete('cascade');
26+
$table->foreignId('permission_id')->constrained()->onDelete('cascade');
27+
});
28+
}
29+
30+
public function down()
31+
{
32+
Schema::dropIfExists('role_permission');
33+
Schema::dropIfExists('permissions');
34+
Schema::dropIfExists('roles');
35+
}
36+
}

0 commit comments

Comments
 (0)