PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, February 2, 2022

[FIXED] Laravel route not defined error when it is clearly defined

 February 02, 2022     laravel, laravel-5, php     No comments   

Issue

I am trying to handle a basic form with laravel and am running in to an issue where my POST route isn't being detected and is resulting in a route not defined error in the blade template. My goal is to resolve this error and post the form to the controller, then access the various form fields with the $request param.

This is the error: Route [become-a-customer] not defined.

I appreciate any suggestions on how to resolve this.

Form

<form action="{{ route('become-a-customer') }}" method="post" class="col-md-8 offset-md-2">
    <div class="form-row">
        <div class="form-group col-md-6">
            <label for="first_name">First Name</label>
            <input name="last_name" type="email" class="form-control" id="first_name" placeholder="First Name">
        </div>
        ...
    </div>
    <input type="hidden" name="_token " value="{{ Session::token() }}"/>
    <button type="submit" class="btn">SUBMIT</button>
</form>

web.php

Route::post('/become-a-customer', 'BecomeACustomerFormController@postBecomeACustomer');

BecomeACustomerController . php

class BecomeACustomerFormController extends Controller
{
    public function postBecomeACustomer(Request $request)
    {
        $firstName = $request['first_name'];
        $lastName = $request['last_name'];
        ...
        ...
        return redirect()->back();
    }
}

Solution

Route::post('/become-a-customer', 'BecomeACustomerFormController@postBecomeACustomer')->name('become-a-customer');


Answered By - Musa
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing