Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fnoual committed Nov 24, 2020
0 parents commit 74deaba
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 0 deletions.
25 changes: 25 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "fnoual/roles",
"description": "Laravel roles system",
"type": "project",
"license": "MIT",
"authors": [
{
"name": "Fawzi Noual",
"email": "[email protected]"
}
],
"require": {},
"autoload": {
"psr-4": {
"Fnoual\\Roles\\" : "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Fnoual\\Roles\\UseRoleServiceProvider"
]
}
}
}
27 changes: 27 additions & 0 deletions src/Console/InstallRolesPackage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Fnoual\Roles\Console;

use Illuminate\Console\Command;

class InstallRolesPackage extends Command
{
protected $signature = 'roles:install';

protected $description = 'Installe le gestionnaire de roles';

public function handle()
{
$this->info('Installation ...');


$this->call('vendor:publish', [
'--provider' => "Fnoual\Roles\UseRoleServiceProvider",
'--tag' => "migrations"
]);

$this->call('migrate');

$this->info('Package installé.');
}
}
12 changes: 12 additions & 0 deletions src/Models/Role.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php


namespace Fnoual\Roles\Models;


use Illuminate\Database\Eloquent\Model;

class Role extends Model
{
protected $table = 'role';
}
13 changes: 13 additions & 0 deletions src/Traits/HasRoles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Fnoual\Roles\Traits;

use Fnoual\Roles\Models\Role;

trait HasRoles
{
public function roles()
{
return $this->belongsToMany(Role::class, 'role_user','user_id','role_id');
}
}
30 changes: 30 additions & 0 deletions src/UseRoleServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Fnoual\Roles;

use Fnoual\Roles\Console\InstallRolesPackage;
use Illuminate\Support\ServiceProvider;

class UseRoleServiceProvider extends ServiceProvider
{
public function register()
{
//
}

public function boot()
{
if ($this->app->runningInConsole()) {
$this->commands([
InstallRolesPackage::class,
]);
}
if ($this->app->runningInConsole()) {
if (! class_exists('CreateRolesTable')) {
$this->publishes([
__DIR__ . '/database/migrations/create_roles_table.php.stub' => database_path('migrations/' . date('Y_m_d_His', time()) . '_create_roles_table.php'),
], 'migrations');
}
}
}
}
34 changes: 34 additions & 0 deletions src/database/migrations/create_roles_table.php.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateRolesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('icon')->default('user');
$table->string('description');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('roles');
}
}

0 comments on commit 74deaba

Please sign in to comment.