【问题标题】:Laravel seeding preg_replace(): errorLaravel 播种 preg_replace(): 错误
【发布时间】:2014-07-28 18:24:18
【问题描述】:

我想知道是否有人可以帮助我。

我在使用播种机在 laravel 中播种数据库时遇到问题,它一直出现此错误:

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

运行 php artisan db:seed 时

有问题的播种机是:GroupTableSeeder.php,文件中的代码是:

<?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);

 }
}

在 DatabaseSeeder.php 我有:

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

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

我正在尝试使用我当前使用的用户角色 https://cartalyst.com/manual/sentry#groups 填充 Groups 表

任何帮助将不胜感激。

干杯, 克里斯

【问题讨论】:

  • 我不确定这是否是问题所在,但看起来您的 $group 中有一个不必要的数组。尝试删除其中一个,看看是否有帮助。

标签: laravel laravel-4 cartalyst-sentry


【解决方案1】:

找到答案,我需要做的:

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

代替:

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

【讨论】:

    猜你喜欢
    • 2014-11-26
    • 1970-01-01
    • 1970-01-01
    • 2017-08-02
    • 2017-07-21
    • 1970-01-01
    • 2014-08-26
    • 2014-12-08
    • 2014-08-14
    相关资源
    最近更新 更多