首页 > 解决方案 > Laravel 播种机给出 TypeError

问题描述

我的项目一切正常,但这个错误突然出现,我无法解决。我可以正常迁移,问题出在播种机上。我不知道是RepublicFactory 的问题还是./libraries/sql.lib.php 的错误。

TypeError 

  Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given, called in /home/naccaratocarolina/Documents/hommy/back-end/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php on line 866

  at vendor/laravel/framework/src/Illuminate/Database/Grammar.php:136
    132|      *
    133|      * @param  array  $values
    134|      * @return string
    135|      */
  > 136|     public function parameterize(array $values)
    137|     {
    138|         return implode(', ', array_map([$this, 'parameter'], $values));
    139|     }
    140| 

      +1 vendor frames 
  2   [internal]:0
      Illuminate\Database\Query\Grammars\Grammar::Illuminate\Database\Query\Grammars\{closure}()

      +13 vendor frames 
  16  database/factories/RepublicFactory.php:13
      Illuminate\Database\Eloquent\FactoryBuilder::create()

RepublicFactory.php:

<?php

use App\Republic;
use Faker\Generator as Faker;
use Illuminate\Support\Str;

$factory->define(Republic::class, function (Faker $faker) {
    return [
        'title' => $faker->name,
        'address' => $faker->address,
        'rental_per_month' => $faker->randomFloat($nbMaxDecimals = NULL, $min = 300, $max = 10000),
        'footage' => $faker->randomFloat($nbMaxDecimals = NULL, $min = 0, $max = 500),
        'user_id' => factory('App\User')->create()->id,
        'number_bath' => $faker->randomDigit,
        'number_bed' => $faker->randomDigit,
        'parking' => $faker->boolean,
        'animals' => $faker->boolean,
        'description' => $faker->realText($maxNbChars = 200, $indexSize = 2),
    ];
});

用户工厂.php

<?php

/** @var \Illuminate\Database\Eloquent\Factory $factory */

use App\User;
use Faker\Generator as Faker;
use Illuminate\Support\Str;

/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| This directory should contain each of the model factory definitions for
| your application. Factories provide a convenient way to generate new
| model instances for testing / seeding your application's database.
|
*/

$factory->define(User::class, function (Faker $faker) {
    return [
        'name' => $faker->name,
        'email' => $faker->unique()->safeEmail,
        'email_verified_at' => now(),
        'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
        'remember_token' => Str::random(10),
    ];
});

并且 phpmyadmin 也给出了一个错误

Notice in ./libraries/DisplayResults.php#1243
 Trying to access array offset on value of type bool

Backtrace

./libraries/DisplayResults.php#1349: PMA\libraries\DisplayResults->_getTableHeadersForColumns(
array,
array,
array,
array,
array,
boolean true,
string '',
)
./libraries/DisplayResults.php#4427: PMA\libraries\DisplayResults->_getTableHeaders(
array,
array,
string '',
array,
array,
array,
boolean true,
)
./libraries/sql.lib.php#1686: PMA\libraries\DisplayResults->getTable(
,
array,
array,
boolean true,
)
./libraries/sql.lib.php#1477: PMA_getHtmlForSqlQueryResultsTable(
,
string './themes/pmahomme/img/',
NULL,
array,
boolean false,
integer 0,
integer 0,
boolean true,
,
array,
boolean true,
)
./libraries/sql.lib.php#2178: PMA_getQueryResponseForNoResultsReturned(
array,
string 'hommy',
string 'users',
NULL,
integer 0,
,
NULL,
string './themes/pmahomme/img/',
,
string 'SELECT * FROM `users`',
NULL,
)
./libraries/sql.lib.php#2062: PMA_executeQueryAndGetQueryResponse(
array,
boolean true,
string 'hommy',
string 'users',
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
string '',
string './themes/pmahomme/img/',
NULL,
NULL,
NULL,
string 'SELECT * FROM `users`',
NULL,
NULL,
)
./sql.php#221: PMA_executeQueryAndSendQueryResponse(
array,
boolean true,
string 'hommy',
string 'users',
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
string '',
string './themes/pmahomme/img/',
NULL,
NULL,
NULL,
string 'SELECT * FROM `users`',
NULL,
NULL,
)

先感谢您!

标签: phpsqllaravelseed

解决方案


推荐阅读