Added seeder for package and updated install / update directions.

This commit is contained in:
Ryan Scherler
2020-04-06 15:21:26 -07:00
parent f716bf88f9
commit 69429afa80
7 changed files with 149 additions and 1 deletions
+14 -1
View File
@@ -22,6 +22,9 @@ cd [appName]
```bash
composer install filament/filament # See note below
php artisan migrate
php artisan vendor:publish --tag=filament-seeds
composer dump-autoload
php artisan db:seed --class=FilamentSeeder
```
> ToDo: Add to Packagist (for now you will need to clone and [symlink the package](https://calebporzio.com/bash-alias-composer-link-use-local-folders-as-composer-dependancies)).
@@ -36,4 +39,14 @@ php artisan filament:user
## Upgrading
There are no special requirements for upgrading, other than changing `^x.xx` version in your composer.json and running `composer update` as well as `php artisan migrate`.
Changing `^x.xx` version in your composer.json.
Run the following commands:
```bash
composer update
php artisan migrate
php artisan vendor:publish --tag=filament-seeds --force
composer dump-autoload
php artisan db:seed --class=FilamentSeeder
```
+39
View File
@@ -0,0 +1,39 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Permissions
|--------------------------------------------------------------------------
|
| The initial system permissions needed by Filament. These are create using
| the `php artisan filament:install` command.
|
*/
[
'name' => 'view users',
'guard_name' => 'web',
'is_system' => 1,
],
[
'name' => 'edit users',
'guard_name' => 'web',
'is_system' => 1,
],
[
'name' => 'create users',
'guard_name' => 'web',
'is_system' => 1,
],
[
'name' => 'edit user permissions',
'guard_name' => 'web',
'is_system' => 1,
],
];
@@ -0,0 +1,43 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddIsSystemToPermissionsTable extends Migration
{
/**
* The name of the table for the migration.
*
* @var string
*/
protected $tableName = 'permissions';
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table($this->tableName, function (Blueprint $table) {
if (!Schema::hasColumn($this->tableName, 'is_system')) {
$table->boolean('is_system')->default(0)->after('guard_name');
}
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table($this->tableName, function (Blueprint $table) {
if (Schema::hasColumn($this->tableName, 'avatar')) {
$table->dropColumn('is_system');
}
});
}
}
@@ -0,0 +1,21 @@
<?php
use Illuminate\Database\Seeder;
use Spatie\Permission\Contracts\Permission as PermissionContract;
class FilamentPermissionSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$permissions = require(Filament::databasePath('data/permissions.php'));
$permissionClass = app(PermissionContract::class);
foreach($permissions as $permission) {
$permissionClass::firstOrCreate($permission);
}
}
}
+16
View File
@@ -0,0 +1,16 @@
<?php
use Illuminate\Database\Seeder;
class FilamentSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->call(FilamentPermissionSeeder::class);
}
}
+11
View File
@@ -20,6 +20,17 @@ class Filament {
return __DIR__.'/../'.ltrim($path, '/');
}
/**
* `database` path
*
* @param string $path
* @return string
*/
public function databasePath($path = '')
{
return $this->basePath('database/'.ltrim($path, '/'));
}
/**
* `route` path
*
+5
View File
@@ -226,6 +226,11 @@ class FilamentServiceProvider extends ServiceProvider
$this->publishes([
$this->packagePath.'config/filament.php' => config_path('filament.php'),
], 'filament-config');
$this->publishes([
$this->packagePath.'database/seeds/FilamentSeeder.php' => database_path('seeds/FilamentSeeder.php'),
$this->packagePath.'database/seeds/FilamentPermissionSeeder.php' => database_path('seeds/FilamentPermissionSeeder.php'),
], 'filament-seeds');
}
}