vendredi 17 février 2017

Laravel 5 /Carbon : Unexpected data found / data missing

I have no idea where to start now. I m just getting started with Laravel and trying to seed a database with random data, using Carbon & Faker. I got this error message :

[InvalidArgumentException]
Unexpected data found.
Unexpected data found.
Unexpected data found.
Data missing

I read several topics that speak of that on SO but nothing that can help me figure out what happening. Im actually following a tutorial so everything should be ok but since I may not be on the same version of Laravel I am not sure (minors changes here and there). Here is my code for the table I try to seed (utilisateursTableSeed.php) :

 <?php

use Illuminate\Database\Seeder;
use Carbon\Carbon;

class utilisateursTableSeeder extends Seeder
{
    private function datealeatoire(){
      return Carbon::createFromDate('null', rand(1,12), rand(1,28));
    }
    /**
    * Run the database seeds.
    *
    * @return void
    */
    public function run()
    {
      DB::table('utilisateurs')->delete();

      $faker = Faker\Factory::create();

      for ($i=0; $i<20; $i++){

        $date=$this->datealeatoire();

        DB:table('utilisateurs')->insert([
          'titre'=> text(50),
          'texte'=>text(),
          'created_at'=>$date,
          'updated_at'=>$date
        ]);
      }
    }
}

My function up() looks like this :

public function up()
{
    Schema::create('utilisateurs', function (Blueprint $table) {
        $table->increments('id');
        $table->string('titre');
        $table->text('texte');
        $table->timestamps();
    });
}

I tried to change the date format but its just getting me some other errors. I have no idea what to do... please tell me if you need more info. I would appreciate any help on this



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire