laravel 7 nothing happens when i click sign up button it seems like event is not triggering

hello and sorry for my bad English , can any one help me ? when i try to sign up nothing happens . i use laravel 7. every time I click the sign up button, nothing happens and also no errors are showing.

UserController.php

namespace App\Http\Controllers\Web\User;

use Reminder;
use Exception;
use Modules\User\Http\Controllers\AuthController;

class UserController extends AuthController
{

    public $routes = [
        'home'            => 'web.home.index',
        'forgot_password' => 'frontend.forgot.password',
        'reset_password'  => 'web.user.reset-password',
    ];

    public function getLogin()
    {
        $return_url = '';
        if ( request()->has('return-url') )
            $return_url .= request()->input('return-url');

        $data = [
            'authenticate_url'  => route('web.user.authenticate', ['return-url' => strip_tags(trim($return_url))])
        ];
        return view('web.user.login', $data);
    }

     /**
     * getNewAccount
     *
     * @return view
     */
    public function getNewAccount()
    {
        return view('web.user.new-account')->with(['url' => route('web.user.post-new-account')]);
    }

     /**
     * Logout current user.
     *
     * @return void
     */
    public function getForgotPassword()
    {
        return view('web.user.forgot-password')->with(['url' => route('web.user.post-forgot-password')]);
    }

    /**
    *
    * getResetPassword()
    *
    * @return template
    * @access  public
    **/
    public function getResetPassword($userHashId,$reminderCode)
    {

        try {

            $hashId = hasher($userHashId,  true);
            if ( !$hashId )
                throw new Exception('Wrong user hash key, please check the url carefully.');

            $user = $this->auth->findById($hashId);

            $isReminderCodeExist = Reminder::exists($user);
            if(!$isReminderCodeExist)
                throw new Exception("Reset code is not exists, please retry.");

            return view('web.user.reset-password')->with(['url' => route('web.user.post-reset-password'),
                                                        'code'    => $reminderCode,
                                                        'hash_code' => $userHashId
                                                    ]);

        } catch (Exception $e) {
            return redirect()->back()->withInput()->withErrors($e->getMessage());
        }
    }

}

new-account.blade.php

@extends( "layouts.master-login")

@section('content')

<div class="row no-gutters justify-content-center ">
    <div class="hero-static col-sm-8 col-md-8 col-xl-8 d-flex align-items-center px-sm-0">

        <div class="col-md-12 col-xl-10" style="margin: 0 auto;">
            <div class="row no-gutters">
                <div class="col-md-6 order-md-1 bg-white">
                    <div class="block-content block-content-full px-lg-5 py-md-5 py-lg-6">
                        <!-- Header -->
                        <div class="mb-2 text-center">
                            <p> @include('common.logo')</p>
                            <p class="text-uppercase font-w700 font-size-sm text-muted"> {{ __('dcm.new_account')}} </p>
                        </div>
                        <!-- END Header -->

                        <!-- Sign In Form -->
                        <form  action="{{ $url }}" method="POST">

                            @if(session('error.message') )
                                <div class="form-group">
                                    <span class="text-danger">{{ session('error.message') }}</span>
                                </div>
                            @endif
                            @csrf
                            <div class="form-group">
                                <input type="text" class="form-control form-control-alt {{ $errors->has('username') ? ' is-invalid' : '' }}"  id="username-username" name="username" placeholder="{{ __('dcm.username_placeholder')}}">
                                {!! $errors->first('username', '<span class="text-danger">:message</span>') !!}
                            </div>
                            <div class="form-group">
                                <input type="text" class="form-control form-control-alt {{ $errors->has('email') ? ' is-invalid' : '' }}"  id="email-email" name="email" placeholder="{{ __('dcm.email_placeholder')}}">
                                {!! $errors->first('email', '<span class="text-danger">:message</span>') !!}
                            </div>
                            <div class="form-group">
                                <input type="text" class="form-control form-control-alt {{ $errors->has('first_name') ? ' is-invalid' : '' }}"  id="first_name-first_name" name="first_name" placeholder="{{ __('dcm.firstname_placeholder')}}">
                                {!! $errors->first('first_name', '<span class="text-danger">:message</span>') !!}
                            </div>
                            <div class="form-group">
                                <input type="text" class="form-control form-control-alt {{ $errors->has('last_name') ? ' is-invalid' : '' }}"  id="last_name-last_name" name="last_name" placeholder="{{ __('dcm.lastname_placeholder')}}">
                                {!! $errors->first('last_name', '<span class="text-danger">:message</span>') !!}
                            </div>
                            <div class="form-group">
                                <input type="password" class="form-control form-control-alt {{ $errors->has('password') ? ' is-invalid' : '' }}" id="password" name="password" placeholder="{{ __('dcm.password_placeholder')}}">
                                {!! $errors->first('password', '<span class="text-danger">:message</span>') !!}
                            </div>
                            <div class="form-group">
                                <button type="submit" class="btn btn-block btn-hero-primary">
                                    <i class="fas fa-plus mr-1"></i> {{ __('dcm.sign_up')}}
                                </button>
                            </div>
                            <hr/>
                            <div class="form-group">
                                <p class="mt-3 mb-0 d-lg-flex justify-content-lg-between">
                                    <a class="btn btn-secondary btn-block d-block d-lg-inline-block mb-1" href="{{ route('web.user.index') }}" title="{{ __('dcm.sign_in')}}">
                                        <i class="fa fa-fw fa-sign-in-alt mr-1"></i> {{ __('dcm.sign_in')}}
                                    </a>
                                </p>
                            </div>
                        </form>
                        <!-- END Sign In Form -->

routes/web/user.php

<?php


// using this pattern to used php artisan route:cache,
// instead of using router closure/grouping.

$userRouteNameSpace = 'Web\User';
$middlewareName     = 'dcm.logged.in';

// UserController
$userController = "{$userRouteNameSpace}\UserController";

// authenticate user
Route::get('user/login', "{$userController}@getLogin")->name('web.user.index');
Route::post('user/authenticate', "{$userController}@postAuthenticate")
        ->name('web.user.authenticate');

// logout user
Route::get('user/logout', "{$userController}@logout")
        ->name('web.user.logout');

// forgot password
Route::get('user/forgot-password', "{$userController}@getForgotPassword")
        ->name('web.user.forgot-password');
Route::post('user/forgot-password', "{$userController}@postForgotPassword")
        ->name('web.user.post-forgot-password');

//  reset password
Route::get('user/reset-password/{hashId}/{resetcode}', "{$userController}@getResetPassword")
        ->name('web.user.reset-password');
Route::post('user/reset-password', "{$userController}@postResetPassword")
        ->name('web.user.post-reset-password');


// create new user account
Route::get('user/new-account', "{$userController}@getNewAccount")
        ->name('web.user.new-account');
Route::post('user/new-account', "{$userController}@postNewAccount")
        ->name('web.user.post-new-account');


// ProfileController
$profileController = "{$userRouteNameSpace}\ProfileController";
Route::get('user/profile', "{$profileController}@getProfile")
        ->name('web.user.profile')
        ->middleware($middlewareName);
Route::post('user/update-profile', "{$profileController}@postUpdateProfile")
        ->name('web.user.update.profile')
        ->middleware($middlewareName);

// update user avatar
Route::post('user/update-avatar/{hashId}', "{$profileController}@postUpdateAvatar")
        ->name('web.user.update.avatar')
        ->middleware($middlewareName);
        
// Verify User

Route::get('/verify','Auth\RegisterController@verifyUser')->name('verify.user');

When I click on sign up, nothing happens, it seems like event is not triggering

1 answer

  • answered 2021-04-15 14:10 Psycho

    First

    Please try to understand carefully, you have your both routes (GET route: get('user/new-account' for new-account page and POST route: post('user/new-account' for getting the values from new-account page) for creating a new user and they are ok. Don't change anything here:

    // create new user account
    Route::get('user/new-account', "{$userController}@getNewAccount")
            ->name('web.user.new-account');
    Route::post('user/new-account', "{$userController}@postNewAccount")
            ->name('web.user.post-new-account');
    

    Second

    As you said, you don't have the method postNewAccount() in your userController so you must have one. So add this code inside your userController so that you can get the submitted data here:

    public function getNewAccount(Request $request)
    {
        // you will get your submitted data here
        // you can either dd() or return to see the submitted data
    
        dd($request->all()); // or return $request->all();
        
        // you can do the rest of the work here
        
    }
    

    If you successfully get data, then you can do next step like validation or storing data to database there.

    Important note: your controller names start with small letter which is also problematic. So, change them like userController will be UserController

    Suggestion:: Please follow the laravel documentation for better understanding the codes before trying them