How can I add muti-dimensional array to laravel database

46 views Asked by At

I want to store product option on my database and loop through it when I retrieve the data. The data structure takes a form

[
  {
    "color": "black",
    "extralCost": 100,
    "size": {
      "xs": 1,
      "sm": 4,
      "L": 2,
      "XL":6
    },
    "stock":13
  }, {
    "color": "white",
    "extralCost": 0,
    "size": {
      "xs": 1,
      "sm": 4,
      "L": 2
    },
    "stock":7
  },
  ...
]

I want to be able to store this in the database and retrieve it at the view.

1

There are 1 answers

3
EXayer On

Add this to your Model.

  protected $casts = [
    'column_name' => 'array',
];

To get an array:

$request->except('_token', '_method')