Search code examples
laravellaravel-4cartalyst-sentry

Laravel seeding preg_replace(): error


I was wondering if someone can help me.

I am having trouble seeding a database in laravel using seeder, it keeps throughing this error:

preg_replace(): Parameter mismatch, pattern is a string while replacement is an array

When running php artisan db:seed

the seeder in question is: GroupTableSeeder.php and the code in the file is:

<?php

class GroupTableSeeder extends Seeder {

public function run()
{

DB::table('groups')->truncate();

$permissions = array( 'system' => 1, );
$group = array(
    array(
        'name' => 'agency', 
        'permissions' => $permissions, 
        'created_at' => new DateTime, 
        'updated_at' => new DateTime
    ),
);

DB::table('groups')->insert($group);

 }
}

In the DatabaseSeeder.php I have:

public function run()
{
    Eloquent::unguard();

    $this->call('GroupTableSeeder');
    $this->command->info('Group table seeded!');
}

I am trying to populate the Groups table with a user role I am currently using https://cartalyst.com/manual/sentry#groups

Any help would be much appreciated.

Cheers, Chris


Solution

  • Found the answer, I needed to do:

    Sentry::getGroupProvider()->create(array(
        'name'        => 'Agency',
        'permissions' => array('admin' => 1),
    ));
    

    Instead of:

    $permissions = array( 'system' => 1, );
    $group = array(
      array(
        'name' => 'agency', 
        'permissions' => $permissions, 
        'created_at' => new DateTime, 
        'updated_at' => new DateTime
      ),
    );