本文整理汇总了PHP中app\models\Post::truncate方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::truncate方法的具体用法?PHP Post::truncate怎么用?PHP Post::truncate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Post
的用法示例。
在下文中一共展示了Post::truncate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Post::truncate();
foreach (range(10, 1) as $num) {
$faker = Faker\Factory::create('zh_TW');
Post::create(['title' => $faker->name, 'content' => $faker->sentence, 'id' => rand(0, 100), 'created_at' => $faker->dateTime($max = 'now'), 'updated_at' => Carbon::now()->subDays($num)->subYears(rand(1, 5))]);
}
}
示例2: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Post::truncate();
$faker = \Faker\Factory::create('zh_TW');
foreach (range(15, 1) as $number) {
Post::create(['title' => $faker->sentence, 'content' => $faker->paragraph, 'is_feature' => rand(0, 1), 'created_at' => Carbon::now()->subDays($number), 'updated_at' => Carbon::now()->subDays($number)]);
}
}
示例3: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Post::truncate();
$faker = Factory::create('zh_tw');
foreach (range(10, 1) as $number) {
Post::create(['title' => $faker->title, 'is_feature' => rand(0, 1), 'content' => $faker->name, 'created_at' => Carbon::now()->subDay($number), 'updated_at' => Carbon::now()->subDay($number)]);
}
}
示例4: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Post::truncate();
$faker = \Faker\Factory::create('zh_TW');
foreach (range(10, 1) as $number) {
Post::create(['title' => $faker->Title, 'content' => $faker->Name, 'is_feature' => rand(0, 1), 'page_view' => rand(1, 1000), 'created_at' => Carbon::now()->subDay($number), 'updated_at' => Carbon::now()->subDay($number)]);
}
}
示例5: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Post::truncate();
foreach (range(1, 10) as $value) {
$faker = \Faker\Factory::create('zh_TW');
Post::create(['title' => $faker->title, 'content' => $faker->name, 'is_feature' => rand(1, 0), 'page_view' => rand(1, 1000), 'created_at' => Carbon::now()->subDays($value), 'updated_at' => Carbon::now()->subDays($value)]);
}
}
示例6: run
public function run()
{
Post::truncate();
$faker = Faker\Factory::create();
$authorIds = User::lists('id');
for ($i = 0; $i < 10; $i++) {
Post::create(['title' => $faker->word, 'desc' => $faker->sentence, 'image_url' => $faker->imageUrl($width = 640, $height = 480), 'share_url' => $faker->url, 'status' => $faker->randomElement(array(0, 1)), 'author_id' => $faker->randomElement($authorIds)]);
}
}
示例7: run
/**
* Seed the posts table
*/
public function run()
{
// Pull all the tag names from the file
$tags = Tag::lists('tag')->all();
Post::truncate();
// Don't forget to truncate the pivot table
DB::table('post_tag_pivot')->truncate();
factory(Post::class, 20)->create()->each(function ($post) use($tags) {
// 30% of the time don't assign a tag
if (mt_rand(1, 100) <= 30) {
return;
}
shuffle($tags);
$postTags = [$tags[0]];
// 30% of the time we're assigning tags, assign 2
if (mt_rand(1, 100) <= 30) {
$postTags[] = $tags[1];
}
$post->syncTags($postTags);
});
}