File tree Expand file tree Collapse file tree 4 files changed +68
-1
lines changed
Expand file tree Collapse file tree 4 files changed +68
-1
lines changed Original file line number Diff line number Diff line change @@ -81,13 +81,23 @@ In Laravel 5.5 the service provider will automatically get registered. In older
8181];
8282```
8383
84+ You can publish [ the migration] ( database/migrations/create_permission_collections.php.stub ) with:
85+
86+ ``` bash
87+ php artisan vendor:publish --provider=" Maklad\Permission\PermissionServiceProvider" --tag=" migrations"
88+ ```
89+
90+ ``` bash
91+ php artisan migrate
92+ ```
93+
8494You can publish the config file with:
8595
8696``` bash
8797php artisan vendor:publish --provider=" Maklad\Permission\PermissionServiceProvider" --tag=" config"
8898```
8999
90- When published, the [ ` config/permission.php ` ] ( https://github.com/mostafamaklad/laravel-permission-mongodb/blob/master/ config/permission.php) config file contains:
100+ When published, the [ ` config/permission.php ` ] ( config/permission.php ) config file contains:
91101
92102``` php
93103return [
@@ -175,6 +185,7 @@ Copy the required files:
175185
176186``` bash
177187cp vendor/mostafamaklad/laravel-permission-mongodb/config/permission.php config/permission.php
188+ cp vendor/mostafamaklad/laravel-permission-mongodb/database/migrations/create_permission_collections.php.stub database/migrations/2018_01_01_000000_create_permission_collections.php
178189```
179190
180191You will also need to create another configuration file at ` config/auth.php ` . Get it on the Laravel repository or just run the following command:
@@ -200,6 +211,12 @@ $app->configure('permission');
200211$app->register(Maklad\Permission\PermissionServiceProvider::class);
201212```
202213
214+ Now, run your migrations:
215+
216+ ``` bash
217+ php artisan migrate
218+ ```
219+
203220## Usage
204221
205222First, add the ` Maklad\Permission\Traits\HasRoles ` trait to your ` User ` model(s):
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Illuminate\Database\Migrations\Migration;
4+ use Illuminate\Support\Facades\Schema;
5+ use Jenssegers\Mongodb\Schema\Blueprint;
6+
7+ class CreatePermissionCollections extends Migration
8+ {
9+ /**
10+ * Run the migrations.
11+ *
12+ * @return void
13+ */
14+ public function up()
15+ {
16+ $collectionNames = config('permission.collection_names');
17+
18+ Schema::table($collectionNames['roles'], function (Blueprint $collection) {
19+ $collection->unique(['name', 'guard_name']);
20+ });
21+
22+ Schema::table($collectionNames['permissions'], function (Blueprint $collection) {
23+ $collection->unique(['name', 'guard_name']);
24+ });
25+ }
26+
27+ /**
28+ * Reverse the migrations.
29+ *
30+ * @return void
31+ */
32+ public function down()
33+ {
34+ $collectionNames = config('permission.collection_names');
35+
36+ Schema::drop($collectionNames['roles']);
37+ Schema::drop($collectionNames['permissions']);
38+ }
39+ }
Original file line number Diff line number Diff line change @@ -21,6 +21,14 @@ public function boot(PermissionRegistrar $permissionLoader)
2121 $ this ->publishes ([
2222 __DIR__ . '/../config/permission.php ' => $ this ->app ->configPath () . '/permission.php ' ,
2323 ], 'config ' );
24+
25+ if (!class_exists ('CreatePermissionTables ' )) {
26+ $ timestamp = date ('Y_m_d_His ' );
27+ $ mFilePath = $ this ->app ->databasePath () . "/migrations/ {$ timestamp }_create_permission_collections.php " ;
28+ $ this ->publishes ([
29+ __DIR__ . '/../database/migrations/create_permission_collections.php.stub ' => $ mFilePath ,
30+ ], 'migrations ' );
31+ }
2432 }
2533
2634 if ($ this ->app ->runningInConsole ()) {
Original file line number Diff line number Diff line change @@ -113,6 +113,9 @@ protected function getEnvironmentSetUp($app)
113113 */
114114 protected function setUpDatabase ($ app )
115115 {
116+ include_once __DIR__ .'/../database/migrations/create_permission_collections.php.stub ' ;
117+ (new \CreatePermissionCollections ())->up ();
118+
116119 User::create (['email ' => 'test@user.com ' ]);
117120 Admin::create (['email ' => 'admin@user.com ' ]);
118121 $ app [Role::class]->create (['name ' => 'testRole ' ]);
You can’t perform that action at this time.
0 commit comments