'How to save data in specific tables based on category in Laravel 8
I am working on a project in Laravel which is basically a report management system. Where there will be many reports and individual information for each report I want to create a separate table for each report. The form of reporting is multi-step. In the first step, the user will select what kind of report it is, for example- if the user selects report-1 then when it saves it will be saved in a report-1 table, or if the user selects report-2 then it will be saved in the report-2 table. Please advise me on how I can do this.
Solution 1:[1]
Step 1: Make two tables report_1_table and report_2_table that each have their individual columns
Step 2: Make two separate models
Step 3:
Make 1 route that will lead to the same controller for both routes. The function this route will point to will contain the logic and will have Request $request as a parameter so that you can retrieve this dropdown using $request->form_type and make an if statement accordingly to then create an object of the correct type like $report1 = new Report1();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dharman |
