douche5961 2015-10-14 13:02
浏览 69
已采纳

在Faker for Laravel 5.0中解析错误

I use "fzaninotto/faker": "^1.5"



<?php
    use Faker\Factory as Faker; use Illuminate\Database\Seeder; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\DB; use Gopro\Served;
    class ServedTableSeeder extends Seeder {
    public function run()  
    {  
        $faker = Faker::create();
        foreach(range(1,20) as $index)  
        {  
            DB::table('server')->insert([  
                'name' => str_replace('.', '_', $faker->unique()->name),  
                'location' => $faker->city,  
                'happytyp_id' => $faker->biasedNumberBetween($min = 1, $max = 8, $function = 'sqrt'),  
                'operatingsystem' => $faker->randomElement($array = array ('Windows 8.1','Windows RT','Windows Server 2012','Windows 7', 'Windows Vista', 'Unix V7', 'AIX', 'A/UX', 'Solaris'),
                'version' => strval($faker->numberBetween($min = 1, $max = 4))
            ]);  
        }
    }
    }

PHP Parse error:

parse error in /Gopro/database/seeds/ServeTableSeeder.php on line 22
And I get the following error: [Symfony\Component\Debug\Exception\FatalErrorException]  
  parse error             

My models and my tables exist and my Databaseseeder.php has on top:

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Gopro\Typ;
use Gopro\Served;

I have done composer dump-autoload. Can someone help me?

I also noticed that there is both

  • 写回答

1条回答 默认 最新

  • dsqnonh2763 2015-10-14 13:26
    关注

    You have a syntax error:

    <?php
    use Faker\Factory as Faker; use Illuminate\Database\Seeder; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\DB; use Gopro\Served;
    class ServedTableSeeder extends Seeder {
        public function run()
        {
            $faker = Faker::create();
            foreach(range(1,20) as $index)
            {
                DB::table('server')->insert([
                    'name' => str_replace('.', '_', $faker->unique()->name),
                    'location' => $faker->city,
                    'happytyp_id' => $faker->biasedNumberBetween($min = 1, $max = 8, $function = 'sqrt'),
                    'operatingsystem' => $faker->randomElement(array('Windows 8.1','Windows RT','Windows Server 2012','Windows 7', 'Windows Vista', 'Unix V7', 'AIX', 'A/UX', 'Solaris')),
            //                                                 ^ removed redundant variable declaration                                                You missed a closing parenthesis ^
                    'version' => strval($faker->numberBetween($min = 1, $max = 4))
                ]);  
            }
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化