Last change
on this file was 0924b6c, checked in by Özkan İliyaz <iliyaz_96@…>, 4 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
439 bytes
|
Line | |
---|
1 | <?php
|
---|
2 |
|
---|
3 | use Illuminate\Database\Seeder;
|
---|
4 | use \Illuminate\Support\Arr;
|
---|
5 | use App\Models\Post;
|
---|
6 |
|
---|
7 | class PostsTagsTableSeeder extends Seeder
|
---|
8 | {
|
---|
9 | /**
|
---|
10 | * Run the database seeds.
|
---|
11 | *
|
---|
12 | * @return void
|
---|
13 | */
|
---|
14 | public function run()
|
---|
15 | {
|
---|
16 | $posts = Post::all();
|
---|
17 |
|
---|
18 | $posts->each(function($item, $key) use($posts) {
|
---|
19 | $item->tag()->attach(Arr::random($posts->pluck("id")->toArray(), rand(2, 5)));
|
---|
20 | });
|
---|
21 | }
|
---|
22 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.