jeudi 22 mars 2018

Laravel - Get price of product in seeder with ID

I'm trying to seed my database. And currently, I'm trying to get the price of a product that has the ID of $index. My seeder looks like this.

foreach(range(1,25) as $index)
    {
        DB::table('orderitems')->insert([

            'order_id' => rand(1, 25),
            'product_id' => $index,
            'price' => '',
            'created_at' => Carbon::now(),
            'updated_at' => Carbon::now(),

        ]);
    }

I foreach this seed 25 times. What I'm trying to achieve is to get the price of each product with the given id. Say, for instance, product_id is 10. I want the price of the product with the ID 10. The relations are fine. I can do something like $product->price and it works fine. How can I achieve this?

the database looks like this

Products
    name
    description
    price
    period

Thanks in advance!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire