Registering new user

  Fri 29 / 12 / 2023

  Posted by: Nouman Hanif

Category : Laravel

Tags : laravel , backend

Description

when i am registering the user this error is occuring again and again the user is not being registered : 

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


View Code
                        public function registerUser(Request $data)
{
    $newUser = new User();
    $newUser->fullname = $data->input('fullname');
    $newUser->email = $data->input('email');
    $newUser->password = Hash::make($data->input('password'));
    $newUser->picture = $data->file('picture')->getClientOriginalName();
    $data->file('picture')->move('uploads/profiles/', $newUser->picture);
    $newUser->type = "Customer";

    if ($newUser->save()) {
        return redirect('login')->with('success', 'Congratulations! Your Account is Ready.');
    }
}              
Regisrer.blade.php form div code : <div class="contact__form">
                    <form action="{{ route('registerUser') }}" method="POST" enctype="multipart/form-data">
                            @csrf
                            <div class="row">
                                <div class="col-lg-6">
                                    <input type="text" name="fullname" placeholder="Name" required>
                                </div>
                                <div class="col-lg-6">
                                    <input type="email" name="email"  placeholder="Email" required>
                                </div>
                                <div class="col-lg-6">
                                    <input type="file" name="picture" required>
                                </div>
                                <div class="col-lg-6">
                                    <input type="password" name="password" placeholder="Password" required>
                                </div>
                                <div class="col-lg-12">
                                    
                                    <button type="submit" class="site-btn">Sign Up</button  >
                                </div>
                            </div>
                        </form>

routes for it : Route::get('/', [MainController::class, 'index']);
Route::get('/cart', [MainController::class, 'cart']);
Route::get('/checkout', [MainController::class, 'checkout']);
Route::get('/details', [MainController::class, 'productDetails']);
Route::get('/shop', [MainController::class, 'shop']);
Route::get('/register', [MainController::class, 'register']);
Route::get('/login', [MainController::class, 'login']);
Route::post('/registerUser', [MainController::class, 'registerUser'])->name('registerUser');
                
  Answered by CDL

Hi Nouman, 

Your code looks fine, maybe the issue you are facing is due to caching, so try to clear your browser and app cache or try with the different browser so it will work as expected.


Let me know if it still won't work for you. 

Solved
  Comment   Share
0 Likes   1 Comment


comment-author
Nouman Hanif Author

i cleared the cache and problem solved JazaakAllah



Reply


commented 8 months ago
comment-author
Hadayat Niazi Super Admin

A pleasure to hear that your problem is resolved.