0

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!

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

Awesome, that sounds like a great plan, I appreciate it.
Sorry, quick question. How can I turn my form into a JSON object if it is dynamic and will change size and variable? Never used JSON before and haven't been able to find this answer.
@gv0029 json_encode($_POST) in the PHP script for the form action should do the trick.
@gv0029 not sure what you're trying to do there. Json_encode inside of your Form::open won't do anything. Just put json_encode(Input::all())) inside of your order-create-post handler to jsonify the form data.
@gv0029 That's why I changed my suggestion to use Input::all() instead of $_POST, pretty sure those don't show up in the laravel Input array. If they do, just use Input::except() to remove the ones you don't need.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.