source: database/seeds/PostsTagsTableSeeder.php

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
3use Illuminate\Database\Seeder;
4use \Illuminate\Support\Arr;
5use App\Models\Post;
6
7class 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.