-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 74deaba
Showing
6 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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é.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |