1.先創建migration

php artisan make:migration create_carts_and_cart_items

2.建立好相關欄位名稱,這邊將carts及cart_items分開建立table

3.執行指令創建table

4.創建后我們先準備一些假資料到product,並到postman看看資料是否都有近來

5.接下來製作cart controller,這邊使用resource幫我們產生index store 等function

php artisan make:controller CartController --resource

6.接著設定路由

7.引入DB套件

8.再取到資料response的時候是一個物件的型態,故我們要轉成array或是collect的型態

public function index()
    {
        $cart = DB::table('carts')->get()->first();
        return response(collect($cart));
    }