public function run() { $faker = Faker::create(); Post::truncate(); foreach (range(1, 20) as $index) { Post::create(['title' => $faker->sentence(5), 'content' => $faker->text(400)]); } }
public function run() { $faker = Faker\Factory::create(); Post::truncate(); foreach (range(1, 30) as $index) { $userId = User::orderBy(DB::raw('RAND()'))->first()->id; Post::create(['user_id' => $userId, 'title' => $faker->sentence(5), 'body' => $faker->paragraph(3)]); } }
public function run() { Post::truncate(); Post::create(['title' => 'Test Post', 'description' => 'This is a test post', 'url' => 'http://www.youtube.com', 'user_id' => '1', 'analytic_id' => '1', 'category_id' => '1']); Post::create(['title' => 'Test Post 2', 'description' => 'This is a test post 2', 'url' => 'http://www.youtube.com', 'user_id' => '1', 'analytic_id' => '1', 'category_id' => '1']); Post::create(['title' => 'Test Post 3', 'description' => 'This is a test post 3', 'url' => 'http://www.youtube.com', 'user_id' => '2', 'analytic_id' => '1', 'category_id' => '1']); Post::create(['title' => 'Test Post 3', 'description' => 'This is a test post 3', 'url' => 'http://www.youtube.com', 'user_id' => '2', 'analytic_id' => '1', 'category_id' => '1']); Post::create(['title' => 'Test Post 3', 'description' => 'This is a test post 3', 'url' => 'http://www.youtube.com', 'user_id' => '2', 'analytic_id' => '1', 'category_id' => '1']); Post::create(['title' => 'Test Post 3', 'description' => 'This is a test post 3', 'url' => 'http://www.youtube.com', 'user_id' => '2', 'analytic_id' => '1', 'category_id' => '1']); }
public function run() { $faker = Faker::create(); $categories = Category::where('parent_id', 0)->get(); $this->categoriesCount = $categories->count(); Post::truncate(); foreach (range(1, 20) as $index) { Post::create(['text' => $faker->paragraph($nbSentences = 3), 'user_id' => $faker->numberBetween($min = 1, $max = 10), 'category_id' => $this->randCat()]); } }
public function run() { $faker = Faker::create(); // delete all existing posts Post::truncate(); for ($i = 0; $i < 50000; $i++) { $post = new Post(); $post->title = $faker->catchPhrase; $post->body = $faker->bs . ' and International' . $faker->bs; $post->user_id = User::all()->random()->id; $post->save(); } }
public function setUp() { $dao = new \VdmDao(); $app = new \App(); $this->myApp = $app->instantiate($dao); // we should create a integration database for test // because we have to truncate the base to test $this->connexion = new \SqliteConnexion(); $this->connexion->load(); \Post::truncate(); for ($i = 1; $i <= 9; $i++) { $newPost = new \Post(array('id' => $i, 'content' => 'My content.', 'date' => DateTime::createFromFormat('Y-m-d H:i:s', '2014-0' . $i . '-01 00:00:00'), 'author' => 'TU_' . $i)); $newPost->save(); } // same author $newPost = new \Post(array('id' => $i, 'content' => 'Ceci est un test PHP Back-End.', 'date' => DateTime::createFromFormat('Y-m-d H:i:s', '2015-01-01 00:00:00'), 'author' => 'TU_' . --$i)); $newPost->save(); }
// depency injection : we should use Pimple with Slim PHP 3 $dao = new \VdmDao(); $nbPostMax = $settings['script']['nbPostLoad']; $settings_db = array('driver' => 'sqlite', 'database' => 'vdm_posts_db.sqlite', 'prefix' => ''); // Bootstrap Eloquent ORM $container = new Container(); $connFactory = new \Illuminate\Database\Connectors\ConnectionFactory($container); $conn = $connFactory->make($settings['database']); $resolver = new \Illuminate\Database\ConnectionResolver(); $resolver->addConnection('default', $conn); $resolver->setDefaultConnection('default'); \Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver); $numberPostsAdded = 0; $page = 0; // delete all lines in table before starting \Post::truncate(); while ($numberPostsAdded < $nbPostMax) { // get page $dom = HtmlDomParser::file_get_html($settings['script']['url'] . '?page=' . $page); // parse all posts in page foreach ($dom->find('div.post') as $post) { if ($numberPostsAdded < $nbPostMax) { // simple php parser can't get directly an object associated with two classes // then we have to filter on article directly after if ($post->class == "post article") { // get id $id = $post->id; // get content which is in multiple tags $content = ''; foreach ($post->find('p', 0)->find('a') as $sentence) { $content .= $sentence->plaintext;
/** * Run the database seeds. * * @return void */ public function run() { // Post::truncate(); Post::create([]); }