There is the following problem with the logic of my web application on Laravel. I have 1 category and 6 subcategories, different data will be added to each subcategory. Example (subcategories and entries): Persons (id, name, age) Construction (id, customer, date, address)
The rest of the tables are in the same form, that is, this is not a relational database, each record does not belong to another.
Categories, subcategories and entries are added from the admin panel to the corresponding tables.
When adding an entry, for example, to the Persons table, I want to see the template only with the text fields I need: Name and age. When adding an entry to Construction: customer, date, address.
Tell me how to implement this logic. As I understand it, under each subcategory you need to use the controller, model and view.blade. But how then to bring all this data to the front end.
P.S. If you asked a question, do not write it correctly, please in the comments I will try to explain in another way ...
Thanks in advance for your answers.
You can try saving subcategories data as JSON string and while retrieving data use json_decode() to parse (as object or array) the JSON string.
Try using two tables - categories and subcategories with the following Schema/Blueprint:
// Category Table
Schema::create('categories', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->text('description')->nullable();
$table->timestamps();
});
// Sub-Category Table
Schema::create('subcategories', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedInteger('category_id');
$table->string('slug'); // (Optional field) Or Slug/Type - to identify persons etc.
$table->string('name');
$table->text('value')->nullable(); // Save Data as json string
$table->timestamps();
});