1

el problema que tengo al realizar las migraciones con sus seeders es:

 Symfony\Component\Debug\Exception\FatalThrowableError  : Argument 1 passed to Illuminate\Database\Grammar::parameterize() 
must be of the type array, integer given, called in C:\laragon\www\PautasUTEM\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php on line 853

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

  Exception trace:

  1   Illuminate\Database\Grammar::parameterize()
      C:\laragon\www\PautasUTEM\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php:853

  2   Illuminate\Database\Query\Grammars\Grammar::Illuminate\Database\Query\Grammars\{closure}("headquarter_id")
      [internal]:0

El problema aparece en la llave foranea que relaciona dos tablas - Migraciones:

Schema::create('headquarters', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('address');
    $table->string('contact');
    // $table->softDeletes();
    $table->timestamps();
});


Schema::create('careers', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('head');
    $table->string('description');

    $table->unsignedInteger('headquarter_id');
    $table->foreign('headquarter_id')->references('id')->on('headquarters');

    // $table->softDeletes();
    $table->timestamps();
});

Estos son los factory:

$factory->define(App\Career::class, function (Faker $faker) {
    return [
        'name'          => $faker->unique()->words(3),
        'head'          => $faker->unique()->words(3),
        'description'   => $faker->sentences(10),
        'headquarter_id' => \App\Headquarter::all()->random()->id,
    ];
});
$factory->define(App\Headquarter::class, function (Faker $faker) {
    return [
        'name'      => $faker->unique()->name,
        'address'   => $faker->unique()->address,
        'contact'   => $faker->unique()->phoneNumber,
    ];
});

Y en los modelos tengo lo siguiente:

class Career extends Model
{
    public function headquarter(){
        return $this->belongsTo(Headquarter::class)->select('id', 'name');
    }
}

class Headquarters extends Model
{
    public function carrers(){
        return $this->hasMany(Career::class);
    }
}

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.