Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

TikTina's avatar

Half of the parts from my form is sent to the table, and the other half don't

I have two forms that I want to be sent to one table called "medical_records". Some of the parts of the form are being sent, and the other don't.

This is the Controller of the first form:

class HealthPredispositionQuestionnaireController extends Controller
{
    public function index()
    {
       return Inertia::render('HealthPredispositionQuestionnaire/Index', [
           'questionnaire' => HealthPredispositionQuestionnaire::all(),
       ]);
    }

    public function questionnaireForm(Request $request)
    {

       $validated =  $this->validate($request, [
            'past_medical_problems' => 'required',
            'current_medications' => 'required',
            'level_of_physical_activity' => 'required',
            'blood_pressure' => 'required',
            'body_temperature' => 'required',
            'heart_rate' => 'required',
            'respiration_rate' => 'required',
            'height' => 'required',
            'weight' => 'required',
            'additional_notes' => 'required',

        ]);

        $validated['user_id'] =\Auth::user()->id;
        $record = MedicalRecord::create($validated);

        
        $record = MedicalRecord::create($request->all());



       return Inertia::render('SymptomsQuestionnaireQuestionnaire/Index', [
           'medicalRecordId' => $record->id
      ]);

    }

}

And this is the Controller of the second form:

class SymptomsQuestionnaireController extends Controller
{
    public function index()
    {
        return Inertia::render('SymptomsQuestionnaire/Index', [
            'symptoms' => Symptoms::all(),

        ]);

    }

    public function symptomsForm(Request $request)
    {

        $validation = $this->validate($request, [
            'symptoms' => 'required',
            'start_of_the_problem' => 'required',
            'area_of_the_pain' => 'required',
            'additional_problems' => 'required'

        ]);

        $record = MedicalRecord::find($request->mrid);
        $record->symptoms = $request->symptoms;
        $record->start_of_the_problem = $request->start_of_the_problem;
        $record->area_of_the_pain = $request->area_of_the_pain;
        $record->additional_problems = $request->additional_problems;



        $record->save();

        dd($record);

        return Inertia::render('SymptomsQuestionnaire/Index', [
            'symptoms' => Symptoms::all(),

        ]);


    }
}

This is the model MedicalRecord:


class MedicalRecord extends Model
{
    use HasFactory;

    public function user()
    {
        return $this->belongsTo(User::class);
    }


    use HasFactory;
    public $fillable = [
        'user_id',
        'past_problems_and_surgeries',
        'current_medications_usage',
        'level_of_physical_activity',
        'blood_pressure',
        'body_temperature',
        'heart_rate',
        'respiration_rate',
        'height',
        'weight',
        'additional_notes',
        'symptoms',
        'when_problem_started',
        'pain_area',
        'pain_intensity',
        'additional_symptoms',
    ];
}
0 likes
30 replies
Sinnbeck's avatar

Can you show the routes for these methods?

TikTina's avatar

@Sinnbeck

Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
    return Inertia::render('Dashboard');
})->name('dashboard');
Route::middleware(['auth:sanctum', 'verified'])->get('/home', function () {
    return Inertia::render('Home');
})->name('home');

Route::middleware(['auth:sanctum', 'verified'])->get('/questionnaire', function () {
    return Inertia::render('HealthPredispositionQuestionnaire');
})->name('questionnaire');

Route::middleware(['auth:sanctum', 'verified'])->get('/symptoms', function () {
    return Inertia::render('SymptomsQuestionnaire');
})->name('symptoms');

Route::middleware(['auth:sanctum', 'verified'])->get('/therapy', function () {
    return Inertia::render('Therapy');
})->name('therapy');

Route::group(['middleware'=> 'auth:sanctum', 'verified'], function(){
    Route::get('/test', [\App\Http\Controllers\HomeController::class, 'test']);
});

Route::post('/home', [App\Http\Controllers\HomeController::class, 'basicForm']);
Route::view("form", "home");

Route::post('/questionnaire', [App\Http\Controllers\HealthPredispositionQuestionnaireController::class, 'questionnaireForm']);
Route::view("form", "questionnaire");

Route::post('/symptoms', [App\Http\Controllers\SymptomsQuestionnaireController::class, 'symptomsForm']);
Route::view("form", "symptoms");

Route::post('/therapy', [App\Http\Controllers\TherapyController::class, 'therapyForm']);
Route::view("form", "therapy");
Sinnbeck's avatar

@TikTina first of you need to have a new get route that just have this info

public function symptoms(MedicalRecord $record)
{
return Inertia::render('SymptomsQuestionnaireQuestionnaire/Index', [
           'medicalRecordId' => $record->id
      ]);

}

//route
Route::get('/symptoms/{record}', [App\Http\Controllers\SymptomsQuestionnaireController::class, 'symptoms']);

You then redirect to this route after you create a new medical record

TikTina's avatar

@Sinnbeck So I put this route with the rest of them, but where will I redirect, in the controller?

Sinnbeck's avatar

@TikTina here

$record = MedicalRecord::create($request->all());

return redirect() //to new route 
//remove the rest 
       return Inertia::render('SymptomsQuestionnaireQuestionnaire/Index', [
           'medicalRecordId' => $record->id
      ]);
 
Sinnbeck's avatar

Just to explain. If you show a page on a page where you save content, the page will have problems if they press reload. Worst case it will create a new record again. Or if you get a validation error on page two it has to go back and create a new record

TikTina's avatar

@Sinnbeck i can't quite follow you, so like this:


  $validated['user_id'] =\Auth::user()->id;
        $record = MedicalRecord::create($validated);


        $record = MedicalRecord::create($request->all());

        return redirect(Route::get('/symptoms/{record}', [App\Http\Controllers\SymptomsQuestionnaireController::class, 'symptoms']));

       return Inertia::render('SymptomsQuestionnaireQuestionnaire/Index', [
           'medicalRecordId' => $record->id
      ]);

    }



Sinnbeck's avatar

@TikTina I recommend checking up on how redirects works. Here is an example (can be cleaned up with named routes)

        $validated['user_id'] =\Auth::user()->id;
        $record = MedicalRecord::create($validated);

        return redirect('/symptoms/'. $record->id);

The route definition goes in the route file, and the method goes in the controller

TikTina's avatar

@Sinnbeck This error come back: BadMethodCallException Method App\Http\Controllers\SymptomsQuestionnaireController::symptoms does not exist.

Sinnbeck's avatar

@TikTina perfect. Then you add it

Here it is

public function symptoms(MedicalRecord $record)
{
return Inertia::render('SymptomsQuestionnaireQuestionnaire/Index', [
           'medicalRecordId' => $record->id
      ]);

}
 
TikTina's avatar

@Sinnbeck Like this:

    $record = MedicalRecord::create($request->all());

        return redirect('/symptoms/'. $record->id);

    }

    public function symptoms(MedicalRecord $record)
    {
        return Inertia::render('SymptomsQuestionnaireQuestionnaire/Index', [
            'medicalRecordId' => $record->id
        ]);

    }

}

TikTina's avatar

@Sinnbeck Yes, I am sorry, I did it...but nothing changed. My form is still not being sent to the database, nor redirecting to the next form :/

Sinnbeck's avatar

@TikTina no worries. Now we can start working on the actual problem. That is why I suggested you created a thread on how to redirect first.

So now if I understand correctly, it now creates a new record and redirects to /symptoms/10 (or some other id)

TikTina's avatar

@Sinnbeck No that is what I want...I have two forms:

  1. HealthPredspositionQuestionnaire
  2. SymptomaticQuestionnaire The patient first needs to fill in the HealthPredspositionQuestionnaire, when filed in it will direct him to the second form (SymptomaticQuestionnaire). And when finished it will get its therapy.

All of the information from the forms should be sent to one the same table in the database medical_record.

And right now, half of the information from the first form is being sent, and the other half don't. And when sent it won't redirect to the second form. And also nothing from the second form won't be sent to the table.

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@TikTina you say

half of the information from the first form is being sent I assume this means this data is being saved?

$validated =  $this->validate($request, [
            'past_medical_problems' => 'required',
            'current_medications' => 'required',
            'level_of_physical_activity' => 'required',
            'blood_pressure' => 'required',
            'body_temperature' => 'required',
            'heart_rate' => 'required',
            'respiration_rate' => 'required',
            'height' => 'required',
            'weight' => 'required',
            'additional_notes' => 'required',

        ]); 
Sinnbeck's avatar

@TikTina great. So the second form. Is that what is shown on SymptomsQuestionnaireQuestionnaire/Index? I assumed it was. If not, which route is it then?

Sinnbeck's avatar

@TikTina so you get to /symptoms/10, and that form is shown? Then what happens?

Sinnbeck's avatar

@TikTina ok where do you redirect to that?

After you create the record you redirect to it

return redirect('/symptoms/'. $record->id);

Do you redirect in Javascript as well?

TikTina's avatar

@Sinnbeck Well in HealthPredispositionQuestionnaire, and SymptomsQuestionnaire

Sinnbeck's avatar

@TikTina sorry you lost me. Any chance the code is on github so I can browse it?

TikTina's avatar

@Sinnbeck I have only the zip, since it Is locked in the git, I am not the administrator. I don't know if I can send the zip here?

Tray2's avatar

@TikTina You can link to it but I guess since the repository is set as private that isn't an option.

Please or to participate in this conversation.