35 lines
770 B
PHP
35 lines
770 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Database\Seeders;
|
||
|
|
|
||
|
|
use App\Models\News;
|
||
|
|
use App\Models\Tag;
|
||
|
|
use Illuminate\Database\Seeder;
|
||
|
|
use Illuminate\Support\Facades\DB;
|
||
|
|
|
||
|
|
class NewsSeeder extends Seeder
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Run the database seeds.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function run()
|
||
|
|
{
|
||
|
|
DB::table('taggables')->truncate();
|
||
|
|
$this->call([
|
||
|
|
TagSeeder::class
|
||
|
|
]);
|
||
|
|
News::truncate();
|
||
|
|
$tags = Tag::query()->get();
|
||
|
|
News::factory(119)->create()
|
||
|
|
->each(function ($model) use ($tags) {
|
||
|
|
$offset = rand(0, 5);
|
||
|
|
$length = rand(1, 4);
|
||
|
|
$model->tags()
|
||
|
|
->saveMany($tags->slice($offset, $length));
|
||
|
|
$model->save();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|