laracastsluvr's avatar

User interface for creating & managing related models

Hello to my favorite forum!

Got a little UI snag that I could use some help with.

Having the following 2 migrations.

...
class CreateSomethingTable extends Migration
{
	Schema::create('somethings', function(Blueprint $table) {
		$table->id;
		$table->string('name');
		$table->text('description')->nullable();
		$table->unsignedInteger('sort_order')->default(0);
	});
}
...
...
class CreateSomethingOptionTable extends Migration
{
	Schema::create('something_options', function(Blueprint $table) {
		$table->id;
		$table->foreignId('something_id');
		$table->string('option_value');
		$table->json('not_relevant');
	});
}
...

Which way is the best way to create a user interface that is used to build out related model objects?

You know, click "Add Something" fill in details and then click on "Add Something Option" and fill in details. Then again click "Add Something" etc. etc. All without leaving the current view.

Client-Side stack is irrelevant, I just want to know how the creation flow should be done.

Does the "Add Something" button make an ajax call to store a new Something model and get back an ID that can be used later on the same "something model" when adding the "Something Options"? And when adding an option do I make a call to get an ID for that? I hate Front-end work because of this, but I need to get this "builder" done.

Does anyone have some resources they can share on how to implement something like a builder UI but not the front-end stuff which is irrelevant. Needs to show how it actually handles data creation/update/deletion.

What I've done so far is the following:

With Vuejs I create an empty array (of somethings) where I add new Something objects and within those I add the something options objects into the something_options array. But handling validation is a nightmare when building out many somethings and options for each something using a single "Builder Interface". Deletion is also an issue on server-side. Which "Something" was removed from the incoming data or which Option was removed from that "something"...

Example:

let somethings = [
	{
		"name" : "A something name",
		"description": "A something description",
		"something_options": [
			{
				"option_value": "An option value",
			},
			{
				"option_value": "Something else",
			}
		]
	},
	{
		"name" : "A something else name",
		"description": "A something  else description",
		"something_options": [
			{
				"option_value": "Another option value",
			}
		]
	}
]

The options must have a Unique ID that is used to retrieve relevant data from the database. Think of a Faceted Search UI but facets need be created with the builder and can't be built-out dynamically from the aggregated buckets.

Thanks in advance for your time!

0 likes
4 replies
double-a's avatar

hi there,

the less users have to click things the better, keep things simple, you dont have to first create the 'somthing' then ask user to add 'somthing options' , put all in a form, make options table-like, starting with one row and the moment user starts to type automatically add next row and a delete button for first.

then when user submit the form, first submit the 'somthing' then when u get the id add the options, without user interaction.

to make life easier i would use Vuex ORM to store the data in vuex, it has Laravel Eloquent inspired api to store,update and query over data

and for validation use Vee-Validate

laracastsluvr's avatar

Yeah, makes sense.

Keep in mind that each "form" contains many Somethings.

Should I just loop through every Something javascript object and send each to the store while getting back the new ID and with that then loop through every option inside that Something object and send each to store ?

Also what about updates to Something and to Options? And deletions?

double-a's avatar

Should I just loop through every Something JavaScript object and send each to the store while getting back the new ID and with that then loop through every option inside that Something object and send each to store ?

this method takes more time to submitting all Somethings, you can loop through Somethings in back-end so you can submit all Somethings with only one request, but you have to make sure u get the response in same order so you be able to get id for items.

another way is to send Somethings individually but batch submit the options, this is easier than my first method and you don't have to make lots of requests for options.

and remember if you choose to make a request for each submit and the total submitting takes time, show user some progress bar so the know everything is working fine, and if some requests couldn't submit for any reason, give user the option to resubmit only those failed ones

laracastsluvr's avatar

Yeah thus far I made it like that. I do the processing on the back-end so I'm sending a big json object from front. The editing is the issue and deletion. I guess the "edit" state of the form should directly delete Somethings and related and also directly delete Options. I also don't know how to approach modification of data in the "Edit" state.

Please or to participate in this conversation.