laravel-seeding

How to pass arguments to Laravel factories?

梦想的初衷 提交于 2019-12-03 05:15:05
I have a users table and a one-to-zero/one relation with a businesses table (users.user_id => businesses.user_id). On my users table I have a discriminator which tells me if the user is of type business and therefore I need to have details on the businesses table as well. I want to create my Users with my factory which currently is working and then only create business details where the discriminator points to a business account. I have three options in my mind: Create from users factory and then using '->each()' do some checks on the discriminator and create a new business user using a the

Laravel 5.3 db:seed command simply doesn't work

余生长醉 提交于 2019-12-03 04:55:42
I do everything by-the-book: Installed fresh Laravel 5.3.9 app (all my non-fresh apps produce the same error) run php artisan make:auth create migrations for a new table `php artisan make:migration create_quotations_table --create=quotations Schema::create('quotations', function (Blueprint $table) { $table->increments('id'); $table->string('text'); // my problem persists even with the below two columns commented out $table->integer('creator_id')->unsigned()->index('creator_id'); $table->integer('updater_id')->unsigned()->index('updater_id'); $table->softDeletes(); $table->timestamps(); });

What is database seeding in Laravel?

做~自己de王妃 提交于 2019-12-01 04:50:43
I use Laravel framework and I have recently been informed that there is something named database seeding which produces a fake dataset for our tests. Is my understanding correct? Well that's pretty much odd. How it works? How it knows which type of data do I need in X column of database? And how it generates it? Also, Can't I make a seed of my real dataset (something like an export) ? You know, I don't know English very well, that's why I cannot understand the concept of seed in database field. Usually you're using model Factories and faker to create fake data (with relations etc) for

What is database seeding in Laravel?

扶醉桌前 提交于 2019-12-01 02:30:02
问题 I use Laravel framework and I have recently been informed that there is something named database seeding which produces a fake dataset for our tests. Is my understanding correct? Well that's pretty much odd. How it works? How it knows which type of data do I need in X column of database? And how it generates it? Also, Can't I make a seed of my real dataset (something like an export) ? You know, I don't know English very well, that's why I cannot understand the concept of seed in database

Laravel 5.2: Unable to locate factory with name [default]

我的梦境 提交于 2019-11-30 11:10:41
I want to seed database when I use this public function run() { $users = factory(app\User::class, 3)->create(); } Add three user in database but when I use this public function run() { $Comment= factory(app\Comment::class, 3)->create(); } Show me error [InvalidArgumentException] Unable to locate factory with name [default] [app\Comment]. By default the laravel installation comes with this code in the database/factories/ModelFactory.php File. $factory->define(App\User::class, function (Faker\Generator $faker) { return [ 'name' => $faker->name, 'email' => $faker->email, 'password' => bcrypt(str

Laravel - Seeding Many-to-Many Relationship

我的未来我决定 提交于 2019-11-30 00:30:04
I have a users table and a roles table that has a many-to-many relationship. These two tables are connected to a junction table called role_user . This is a model of the tables and its connections. Below are the Models in my Laravel project: User namespace App; use Illuminate\Database\Eloquent\Model; class Role extends Model { public function roles() { return $this->belongsToMany('App\Role'); } } Role namespace App; use Illuminate\Database\Eloquent\Model; class Role extends Model { public function users() { return $this->belongsToMany('App\User'); } } Below is the Factory file in the Laravel

Laravel 5.2: Unable to locate factory with name [default]

℡╲_俬逩灬. 提交于 2019-11-29 10:43:25
问题 I want to seed database when I use this public function run() { $users = factory(app\User::class, 3)->create(); } Add three user in database but when I use this public function run() { $Comment= factory(app\Comment::class, 3)->create(); } Show me error [InvalidArgumentException] Unable to locate factory with name [default] [app\Comment]. 回答1: By default the laravel installation comes with this code in the database/factories/ModelFactory.php File. $factory->define(App\User::class, function

Laravel - Seeding Many-to-Many Relationship

Deadly 提交于 2019-11-28 21:26:40
问题 I have a users table and a roles table that has a many-to-many relationship. These two tables are connected to a junction table called role_user . This is a model of the tables and its connections. Below are the Models in my Laravel project: User namespace App; use Illuminate\Database\Eloquent\Model; class Role extends Model { public function roles() { return $this->belongsToMany('App\Role'); } } Role namespace App; use Illuminate\Database\Eloquent\Model; class Role extends Model { public

Database gets stuck in migration with seeder on production with --force in Laravel 5

 ̄綄美尐妖づ 提交于 2019-11-28 05:42:18
问题 Database gets stuck in migration with seeder on production with --force in Laravel. Same effect I have on Laravel Homestead and EC2 AWS running Amazone linux. No messages in laravel.log. It just never ends. If I halt it with <ctrl>+<c> , I see the table created but seeder was not run, the table is empty. Detalis: My migration: public function up() { Schema::create('products', function (Blueprint $table) { $table->increments('id'); $table->string('name', 50); $table->decimal('price', 8, 2); /