jeudi 27 février 2020

From validation Throws error The GET method is not supported for this route. Supported methods: POST."

i am new to laravel..Kind of stuck at this place. Tried many solutions for this but none worked yet, There are similar question but most unresolved, or proper evident solution not posted yet(from google,stackoverflow ..etc)

i have defned a custom route

Route::post('/ComplaintGenerate', 'ComplaintsController@generate'); 

whenever i submit the view with 'POST' method as

<form action="/ComplaintGenerate" method="POST" > 

without any validation rule in my Complaintscontroller everything works fine and i can save data. but when i put validation either through Requests or direct it throws error Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException The GET method is not supported for this route. Supported methods: POST.

if i remove validation everything works fine. I also tried with GET method but still dint work. A little peace of advice will be very much appreciated.

Web.route

Route::middleware(['auth'])->group(function(){
Route::post('/Complaint', 'ComplaintsController@find'); 
Route::post('/ComplaintGenerate', 'ComplaintsController@generate');
Route::post('/Complaint/{Complaint}', 'ComplaintsController@save_customer');
Route::resource('Complaints', 'ComplaintsController');
Route::resource('Occupancies', 'OccupanciesController');
Route::resource('Customers', 'CustomersController');
Route::resource('Services', 'ServiceController');
Route::resource('ServiceTeams', 'ServiceTeamController');
Route::get('/home', 'HomeController@index')->name('home');});

My controller:

public function generate(GenerateInitialComplaintRequest $request)
{  
    $complaint = Complaint::find($request->complaint_id);
    $complaint->update([
        'complaint_date'=>$request->complaint_date,
        'complaint_description'=>$request->complaint_description,   
    ]);

    return redirect(route('Complaints.index')->with('complaint', Complaint::all()));           
}

my View:

<div class="container my-5">

<div class="col d-flex justify-content-center my-4">
    <div class="card">
        <div class="card-header">

            <form action="/ComplaintGenerate" method="POST" >
          @csrf
          @if ($errors->any())
                <div class="alert alert-danger">
                    <ul>
                        @foreach ($errors->all() as $error)
                            <li></li>
                        @endforeach
                    </ul>
                </div>
            @endif
          <div class="form-row">
            <div class="form-group col-md-6">
              <label for="complaint_id">Complaint Number</label>
              <input type="text" class="form-control" id="complaint_id" name="complaint_id" value="" readonly >
            </div>
            <div class="form-group col-md-6">
              <label for="complaint_date">Complaint Date</label>
              <input type="text" class="form-control" id="complaint_date" name="complaint_date">
            </div>
          </div>

          <div class="form-row">
            <div class="form-group  col-md-12">
              <label for="complaint_description">Complaint Description</label>
              <textarea class="form-control" id="complaint_description" name="complaint_description" rows="5"></textarea>
            </div>
          </div>             
         <div class="text-center">
             <button type="submit" class="btn btn-primary">Save</button>                
         </div>
    </form>
        </div>
    </div>
</div>


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire