Don't you speak portuguese? Translate this site with Google Translator

Pensamento do Dia

Na maior parte dos homens, as dificuldades são filhas da preguiça. (Samuel Johnson)

Faker com Laravel

Usando o Faker para gerar dados de teste para as tabelas

Detalhes sobre o Faker

https://github.com/fzaninotto/Faker

Faker com seed
php artisan make:seeder ClientesTableSeeder

Exemplos


<?php

use Illuminate\Database\Seeder;
use Faker\Factory as Faker;

class ClientesTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$faker = Faker::create();
foreach (range(1,100) as $index) {
DB::table('clientes')->insert([
'nome' => $faker->name,
'nascimento' => $faker->dateTime($max = 'now'),
'fone' => $faker->tollFreePhoneNumber,
'observacao' => $faker->catchPhrase,
'created_at' => \Carbon\Carbon::createFromDate(2017,05,24)->toDateTimeString(),
'updated_at' => \Carbon\Carbon::createFromDate(2017,05,24)->toDateTimeString()
]);
}
}
}

$faker = Faker::create();
foreach (range(1,5) as $index) {
DB::table('users')->insert([
'name' => $faker->name,
'email' => $faker->email,
'password' => bcrypt('123456'),
'created_at' => \Carbon\Carbon::createFromDate(2017,05,24)->toDateTimeString(),
'updated_at' => \Carbon\Carbon::createFromDate(2017,05,24)->toDateTimeString()
]);
}

$faker = Faker::create();
foreach (range(1,100) as $index) {
DB::table('posts')->insert([
'user_id' => $faker->numberBetween($min = 1, $max = 5),
'title' => $faker->name,
'description' => $faker->catchPhrase,
'created_at' => \Carbon\Carbon::createFromDate(2017,05,24)->toDateTimeString(),
'updated_at' => \Carbon\Carbon::createFromDate(2017,05,24)->toDateTimeString()
]);
}

$faker = Faker::create();
foreach (range(1,100) as $index) {
DB::table('pedidos')->insert([
'cliente_id' => $faker->numberBetween($min = 1, $max = 100),
'vendedore_id' => $faker->numberBetween($min = 1, $max = 100),
'data' => $faker->dateTime($max = 'now'),
'created_at' => \Carbon\Carbon::createFromDate(2017,05,24)->toDateTimeString(),
'updated_at' => \Carbon\Carbon::createFromDate(2017,05,24)->toDateTimeString()
]);
}

$faker = Faker::create();
foreach (range(1,100) as $index) {
DB::table('pedido_itens')->insert([
'estoque_id' => $faker->numberBetween($min = 1, $max = 100),
'quantidade' => $faker->regexify('[1-9]{2,4}'),
'preco' => $faker->regexify('[1-9]{4,6}'),
'pedido_id' => $faker->numberBetween($min = 1, $max = 100),
'created_at' => \Carbon\Carbon::createFromDate(2017,05,24)->toDateTimeString(),
'updated_at' => \Carbon\Carbon::createFromDate(2017,05,24)->toDateTimeString()
]);
}

Rodando o seed apenas na tabela Clientes
php artisan db:seed --class=ClientesTableSeeder

'first_name' => $faker->firstName,
'last_name' => $faker->lastName,
'username' => str_replace('.', '_', $faker->unique()->userName),
'email' => $faker->email,
'password' => $faker->word,
'active' => $faker->boolean($chanceOfGettingTrue = 90),
'role_id' => rand(3,5)
'address' => $faker->address,
'DOB' => $faker->date('Y-m-d')
$faker->randomNumber

$faker = Faker::create();
foreach (range(1,100) as $index) {
DB::table('clientes')->insert([
'nome' => $faker->name,
'cpf' => $faker->numberBetween($min = 10000000000, $max = 90009999999),
'nascimento' => $faker->dateTime($max = 'now'),
'email' => $faker->email,
'created_at' => \Carbon\Carbon::createFromDate(2017,05,24)->toDateTimeString(),
'updated_at' => \Carbon\Carbon::createFromDate(2017,05,24)->toDateTimeString()
]);
}

Comments fornecido por CComment

Novo Testamento

E, chegando os que tinham ido perto da hora undécima, receberam um dinheiro cada um.
(Mt, 20:9)

Rotas no Mapa do Google

© 2015 Ribamar FS. All Rights Reserved. Designed By JoomShaper