Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purpose and implemetnation of json field type in laravel schema builder

what is purpose of $table->json('options'); as field type of laravel database schema builder.I tried searching hard but couldn't get any relevant info on it.Please some one state list purpose with example

like image 293
Sumit Avatar asked Mar 15 '23 10:03

Sumit


1 Answers

Some database engines - PostgreSQL being a major example - have JSON-friendly data types (that MySQL currently lacks - it'll just store as a TEXT data type there). This can be handy for working with data (like the options example you cite) that might contain a large amount of schema-less or loosely-structured data.

  • http://www.postgresql.org/docs/9.4/static/datatype-json.html
  • http://www.postgresql.org/docs/9.3/static/functions-json.html

Instead of having 100+ columns for a bunch of on/off options for a model, you could store them in a JSON object in the database.

like image 172
ceejayoz Avatar answered Mar 17 '23 23:03

ceejayoz