In this video we are going to learn about Store And Display Product Attributes With Order
So let see how can we Store And Display Product Attributes With Order
First of all lets add a column inside the order_items for storing the
product attributes details
So switch to the command prompt and run the command


php artisan make:migration add_options_to_order_items_table –table=order_items


Now switch to the project and lets open the migration
And here lets add a column so write here


public function up()
{
Schema::table('order_items', function (Blueprint $table) {
$table->longText('options')->nullable();
});
}

public function down()
{
Schema::table('order_items', function (Blueprint $table) {
$table->dropColumn('options');
});
}


Now save this and lets migrate this migration
So switch to the command prompt and run the command


php artisan migrate


Alright now run the application


php artisan serve


Now switch to the project and lets open the CheckoutComponent.php class file
And here inside the placeOrder function
Inside the foreach lets store the product attributes
So write here


if($item->options)
{
$orderItem->options = serialize($item->options);
}


Now its done so lets check it
So lets add a product to the cart and now click on checkout
Add the checkout details and now click on place order and here you can see the message order placed successfully
Now lets check the table so go to the phpMyAdmin and open the database
Now lets browse the order_items table
And here you can see the ordered items with attributes value
Alright now lets show this order attributes on user order details page
So go inside the user folder then open user-order-detailscomponent.blade.php view file
And here after this name lets display the product attribute as following


@if($item->options)
<div class="product-name">
@foreach(unserialize($item->options) as $key => $value)
<p><b>{{$key}}:{{$value}}</b></p>
@endforeach
</div>
@endif


Now lets check it
So switch to browser and refresh the page
Now go to the my orders and lets view details of this order so click here
And here you can see the product attributes
Now lets display the product attribute in admin-order-details page

So go inside the admin directory then open
admin-order-details component view file and here add the following code.


@if($item->options)
<div class="product-name">
@foreach(unserialize($item->options) as $key => $value)
<p><b>{{$key}}:{{$value}}</b></p>
@endforeach
</div>
@endif


Now save this and lets check it
So switch to the browser and
First of all lets logout from user account
And login with admin credentials
Now go to the All orders page
Now lets open this product details page
so click here and you can see the product attributes here
So in this way you can Store And Display Product Attributes With Order