Home > Back-end >  Laravel redirect code 302 when submit form
Laravel redirect code 302 when submit form

Time:12-03

I faced an issue where Laravel redirects me back to my form page after submitting the form. I was trying to return my $request data to make sure I got the correct values. But I ended up getting redirected back to the form. enter image description here Controller:

// ServiceController.php
public function saveServiceProgress(Request $request, $id)
    {
        $service = Service::find($id);
        
        $rules = $this->generateCustomRules($service);
        $request->validate($rules);
        $input = $request->all();
        return $request;
        // echo $input;
        // return view('services.edit', compact('service'));
    }

The form is a huge form with switch case, so I only show the form tag:

{!! Form::open(['route' => ['services.saveServiceProgress', 'id' => $service->id],'method'=>'POST', 'files'=>'true']) !!}

The form consists for dynamic input based on the id passed into the controller. It has text inputs and file inputs as well. So its a very complex form. Currently I chose the simplest version of the form to test the functionalities.

Please shed some light (and probably some code) to help me with my problems! Thanks a lot!!!

Update on route:

Route::post('services/submit/{id}', [ServiceController::class, 'saveServiceProgress'])->name('services.saveServiceProgress');

Update after fixing validator: Managed to submit the form, now starts working on handling file upload. Thanks @Rwd and @mahmoud\ magdy for pointing out my validation issues!

CodePudding user response:

use Validator::make to handle if yours validation if fails with custom errors response

see this link https://laravel.com/docs/8.x/validation#manually-creating-validators

  • Related