mario
mario

Reputation: 1543

Storing Dynamic Data with a Relational Database with Laravel 4

I was wondering how can I store data from a dynamic form, which might have 10 variables or 100 depending on the user, and still take advantage of the relational database abilities of Laravel? Usually I would just serialize the form but that seems like it would be wasting a lot of Laravel's potential. Any and all thoughts on this would be greatly appreciated! Thank y'all so much!

Upvotes: 0

Views: 667

Answers (1)

Tony Arra
Tony Arra

Reputation: 11099

Couple alternatives to serialization:

  1. Using SQL: store your data in a single Text/String field using a JSON object. You can include the logic inside of your model to parse/generate that JSON object. For example,

    $model->fill(json_decode($jsonified_array, true)) will allow the Eloquent model to behave as if it just grabbed a bunch of fields from a table.

  2. Using NoSQL: you could try something like a MongoDB bundle for Laravel. MongoDB is a Document-Oriented DMS, an alternative to relational databases (such as SQL). It works better for "unstructured" data, such as what you're describing. It's extremely similar to storing your data in JSON Objects, but at a binary level, making it much more efficient.

Recommend option #1 personally, since I typically need to use relational databases, but it depends on the requirements of your program and your personal preferences.

Upvotes: 1

Related Questions