You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
605 B
31 lines
605 B
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
|
|
use App\Models\Product;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class LikesProductsTableSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run()
|
|
{
|
|
$products = Product::all()->pluck('id')->toArray();
|
|
|
|
User::all()->each(function($u) use ($products) {
|
|
|
|
shuffle($products);
|
|
$start = mt_rand(0, count($products) - 1);
|
|
$product_ids = array_slice($products, $start);
|
|
|
|
$u->products()->attach($product_ids);
|
|
});
|
|
}
|
|
}
|