I get the error "PHP Fatal error: Call to a member function getKey () on string"

0

When executing via console php artisan db:seed I get the following error PHP Fatal error: Call to a member function getKey () on string

The error occurs precisely with a function of the Seeder since with other functions it gave the expected results.

Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Cviebrock\EloquentSluggable\Sluggable;
//use Cviebrock\EloquentSluggable\SluggableScopeHelpers;


class Categoria extends Model{
    use Sluggable; //SluggableScopeHelpers

     /**
      * Return the sluggable configuration array for this model.
      *
      * @return array
      */
    public function sluggable(){
        return [
            'slug' => [
                'source' => 'nombre'
            ]
        ];
    }

    protected $table = 'categorias';

    protected $fillable = ['nombre','slug','descripcion','color'];

    public $timestamps = false;

}

The ModelFactory

$factory->define(App\Categoria::class, function(Faker\Generator $faker) {
    return[
        'nombre' => $faker->randomElement(['Camisa de Jean','Camisa Oxford','Guayaberas', 'Guardacamisas','Camisa de vestir']), //Para elegir nombres random
        'descripcion' => $faker->paragraph, //Para escribir textos largos
        'color' => $faker->randomElement(['Azul','Verde','Rojo', 'Negra','Amarilla','Gris']), //Para elegir colores random
    ];
});

DatabaseSeeder

<?php

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;

class DatabaseSeeder extends Seeder{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run(){

        Model::unguard();

        //factory('App\User',10)->create();
        factory('App\Categoria',8)->create();
        //factory('App\Producto',20)->create();
        // $this->call(UserTableSeeder::class);

        Model::reguard();
    }
}

MIGRATION OF THE TABLE CATEGORIES

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCategoriasTable extends Migration{

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up(){

        Schema::create('categorias', function (Blueprint $table) {

            $table->increments('id');
            $table->string('nombre');
            $table->string('slug');
            $table->text('descripcion');
            $table->string('color');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down(){
        Schema::drop('categorias');
    }
}

THE OTHER FUNCTIONS IN THE MODELFACTORY I DO NOT KNOW ARE EXECUTING THEREFORE I DO NOT SHOW THEM IN MY CODES

    
asked by Luis Morales 17.02.2017 в 00:53
source

1 answer

1

After so much struggle, I BELIEVE that I reach a possible solution, it is not definitive but it can accommodate if someone happens the same mistake ...

In the file config/sluggable.php you can see that around line 65 we get the following

/**
 * Enforce uniqueness of slugs?  Defaults to true.
 * If a generated slug already exists, an incremental numeric
 * value will be appended to the end until a unique slug is found.  e.g.:
 *
 *     my-slug
 *     my-slug-1
 *     my-slug-2
 */

'unique' => true,

According to this it means that the value of our slug will be unique and that is why I could not create many fields because the random order got the same and took the random order for granted.

    
answered by 17.02.2017 в 03:56