phpmaven
3 months ago

Add rows to database collection

Posted 3 months ago by phpmaven

I'm creating a collection using the following code:

                    $attributes = DB::table('product_attribs')
                    ->where('Attrib_SKU', '=', $request->query('SKU'))
                    ->orderBy('Attrib_Seq', 'asc')
                    ->get();

I'm trying to figure out how to add additional rows to the collection.

I tried doing this, but it ends up adding arrays to the collection:

                    $attributes->push([
                    'Attrib_SKU'=>  'ichhar', 
                    'Attrib_Seq'=>  'uploads/pub.jpg',
                    'Attrib_Standard'=> '',
                    'Attrib_Name'=> '',
                    'Attrib_Type'=> '',
                    'Attrib_Size'=> '',
                    'Attrib_Initial_Value'=> '',
                    'Attrib_Supress'=> '',
                    'Attrib_Label'=> '',
                    'Attrib_Required'=> '',
                    'Attrib_Value'=> '',
                    'Attrib_Valid_Type'=> '',
                    'Attrib_Valid_Msg'=> '',
                    'Attrib_Dependency'=> '',
                    'OridinalLabel'=> '' ]);

In C# for example I would create a new object based on the product_attribs model and add that to the collection. Is there a way to do something similar in Laravel?

Thanks

Please sign in or create an account to participate in this conversation.