Laravel : How to store json format data in database?

后端 未结 3 780
梦谈多话
梦谈多话 2020-12-29 09:17

I want to store some json format data in database from a given array. But How i do store it using controller.

Suppose I have json data like :

{\"id\"         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-29 09:30

    You can convert your Model to JSON format like $model->toJson();

    or

    if you have data in an array you can use json_encode(['id' => 1, 'name' => 'User 1']);

    Laravel Schema does support JSON field types as well look https://laravel.com/docs/5.0/schema#adding-columns

    You can use text field type as well to store JSON data.

提交回复
热议问题