-
In our test environment migration and seeding for a new Laravel application worked just fine.
PermissionSeeder.php: <?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
use Spatie\Permission\PermissionRegistrar;
class PermissionsSeeder extends Seeder
{
// protected $connection = 'te_base'; Denne funker desverre ikke
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// Reset cached roles and permissions
app()[PermissionRegistrar::class]->forgetCachedPermissions();
// create permissions
Permission::create(['name' => 'administer access']);
Permission::create(['name' => 'maintain metadata']);
Permission::create(['name' => 'export']);
Permission::create(['name' => 'edit']);
// create roles and assign existing permissions
$roleAdmin = Role::create(['name' => 'admin']);
$roleAM = Role::create(['name' => 'AM']);
$roleExporter = Role::create(['name' => 'exporter']);
// gets all permissions via Gate::before rule; see AuthServiceProvider
$roleAdmin->givePermissionTo('administer access');
$roleAM->givePermissionTo('maintain metadata');
$roleExporter->givePermissionTo(['export', 'edit']);
// create users
$user = \App\Models\User::factory()->create([
'userid' => 'someuser',
'name' => 'Me',
'email' => '[email protected]',
]);
$user->assignRole($roleAdmin);
$user->assignRole($roleExporter);
$user->assignRole($roleAM);
}
} What could be wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Could be some data you're setting in your UserFactory. Can you post that file's code? Although, I'm surprised it's suggesting a problem in the "select * from permissions" query. But maybe that's secondary. |
Beta Was this translation helpful? Give feedback.
-
Solved by redeploy. |
Beta Was this translation helpful? Give feedback.
Thanks for your input, @drbyte ! :-)
I have not changed UserFactor so I don't think the problem is there.
Laziness some times creates problems. I had copied a test deployment to production. After running a proper production deployment (using Deployer) seeding now worked. It should be the same but obviously wasn't. I am afraid this means I don't know what really solved the problem