Home > Blockchain >  The POST method is not supported for route register. Supported methods: GET, HEAD Laravel
The POST method is not supported for route register. Supported methods: GET, HEAD Laravel

Time:02-03

i am going to make a registation form in laravel when i registered the user and click submit button. i got the error was The POST method is not supported for route register. Supported methods: GET, HEAD.

what i tried so far i attached below.

Routes

Route::post('register', [RegisterContoller::class])->name('register');

Views

@extends('layout')
@section('content')
  
    <div >
        <div >Contact Form</div>
        <div > 
        
            <form action= "{{ route('register') }}" method="post">
             {!! csrf_field() !!}   
            <label>First Name</label>
            <input type="text" name="fname" id="fname" class ="form-control"> </br>

            <label>Last Name</label>
            <input type="text" name="lname" id="lname" class ="form-control"> </br>

            <label>Email</label>
            <input type="email" name="email" id="email" class ="form-control"> </br>


            <label>Password</label>
            <input type="password" name="password" id="password" class ="form-control"> </br>


            <input type="submit" value="Save" > 


            </form>
        </div>
    </div>

@stop

Contoller

class RegisterContoller extends Controller
{
    public function create()
    {
        return view('contact.create');
    }

    public function store(Request $request)
    {
       $input = $request->all();
       Register::Create($input);
       return view('contact.thanks');
    }
}

Model

class Register extends Model
{

    protected $table = "register";
    protected $primarykey = "id";
    protected $fillable = ["fname","lname","email","password"];



    use HasFactory;
}

routes images enter image description here

CodePudding user response:

There isn't any method called register. store method is where you call the Register::Create method, passing it the input from form.

The route has to be like this:

Route::post('/register', [RegisterContoller::class, 'store'])->name('register');

EDIT:

Running the following command should work:

php artisan route:cache
php artisan route:clear

These will clear the routes cache.

  • Related