本文整理汇总了PHP中Post::truncate方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::truncate方法的具体用法?PHP Post::truncate怎么用?PHP Post::truncate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Post
的用法示例。
在下文中一共展示了Post::truncate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
$faker = Faker::create();
Post::truncate();
foreach (range(1, 20) as $index) {
Post::create(['title' => $faker->sentence(5), 'content' => $faker->text(400)]);
}
}
示例2: run
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)]);
}
}
示例3: run
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']);
}
示例4: run
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()]);
}
}
示例5: run
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();
}
}
示例6: setUp
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();
}
示例7: array
// 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;
示例8: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//
Post::truncate();
Post::create([]);
}