Laravel 5.6 - Registration Form is not working and does not show any error

laravel custom validation message
laravel witherrors
laravel 6 validation
laravel 5.6 login error message
laravel registration form
laravel registration form validation
laravel validation float
custom register form in laravel

In one of my recent project, the custom registration form is not working. When I click on the register button, it reloads the registration form, does not print any error and no data is inserted into the database. Here is the look of the registration form:

Here is the migration file code:

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('fname');
        $table->string('lname');
        $table->string('email')->unique();
        $table->string('contact');
        $table->string('password');
        $table->string('created_by');
        $table->string('modified_by')->nullable();
        $table->string('userrole');
        $table->rememberToken();
        $table->timestamps();
    });
}

Here is the code of User Model:

protected $fillable = [
    'fname', 'lname', 'email', 'password', 'contact', 'created_by', 'userrole',
];

protected $hidden = [
    'password', 'remember_token', 'modified_by',
];

Here is the code of RegisterController:

protected function create(array $data)
{
    return User::create([
        'fname' => $data['fname'],
        'lname' => $data['lname'],
        'email' => $data['email'],
        'contact' => $data['contact'],
        'created_by' => $data['email'],
        'userrole' => Config::get('constants.ROLE_USER'),
        'password' => Hash::make($data['password']),
    ]);
}

Here is the code of constants.php, which is inside config folder:

<?php
    return array(
        'ROLE_ADMIN' => 'ROLE_ADMIN',
        'ROLE_USER' => 'ROLE_USER'
    );

And finally, here is the code of register.blade.php file:

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header bg-dark text-white">{{ __('Register') }}</div>

                <div class="card-body">
                    <form method="POST" action="{{ route('register') }}">
                        @csrf

                        <div class="form-group row">
                            <label for="fname" class="col-md-4 col-form-label text-md-right">{{ __('First Name') }}</label>

                            <div class="col-md-6">
                                <input id="fname" type="text" class="form-control{{ $errors->has('fname') ? ' is-invalid' : '' }}" name="fname" value="{{ old('fname') }}" required autofocus>

                                @if ($errors->has('fname'))
                                    <span class="invalid-feedback">
                                        <strong>{{ $errors->first('fname') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="lname" class="col-md-4 col-form-label text-md-right">{{ __('Last Name') }}</label>

                            <div class="col-md-6">
                                <input id="lname" type="text" class="form-control{{ $errors->has('lname') ? ' is-invalid' : '' }}" name="lname" value="{{ old('lname') }}" required>

                                @if ($errors->has('lname'))
                                    <span class="invalid-feedback">
                                        <strong>{{ $errors->first('lname') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>

                            <div class="col-md-6">
                                <input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email') }}" required>

                                @if ($errors->has('email'))
                                    <span class="invalid-feedback">
                                        <strong>{{ $errors->first('email') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="contact" class="col-md-4 col-form-label text-md-right">{{ __('Contact No') }}</label>

                            <div class="col-md-6">
                                <input id="contact" type="text" class="form-control{{ $errors->has('contact') ? ' is-invalid' : '' }}" name="contact" value="{{ old('contact') }}" required>

                                @if ($errors->has('contact'))
                                    <span class="invalid-feedback">
                                        <strong>{{ $errors->first('contact') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>

                            <div class="col-md-6">
                                <input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" required>

                                @if ($errors->has('password'))
                                    <span class="invalid-feedback">
                                        <strong>{{ $errors->first('password') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</label>

                            <div class="col-md-6">
                                <input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
                            </div>
                        </div>

                        <div class="form-group row mb-0">
                            <div class="col-md-6 offset-md-5">
                                <button type="submit" class="btn btn-primary">
                                    {{ __('Register') }}
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
     </div>
</div>
@endsection

Here is a short clip of my problem: Video Clips

So, can anyone help me to figure out, what is the actual problem? How can I solve that problem?

  • Thanks

It may be because you have @csrf and not {{ csrf_field }} so the CSRF Token is not get posted.

Also, just for testing you can try to add this to your blade:

@if ($errors->any())    
    <ul>
    @foreach ($errors->all() as $error)
        <li>{{ $error }}</li>
    @endforeach
    </ul>
@endif

You can also add this to your Controller action to see exactly what is getting posted:

dd(request()->all());

But be aware of any Requests that may be doing any validation on the action

Laravel 5.6 register doesn't work, no redirect and no errors (edited register fields) the default php artisan make:auth User database + registration form. and nothing gets added to the database nor do I get an error message. it has something to do with my problem because my register.blade.php sends  Problem with registration user data | Laravel 5.6 Posted 2 years ago by NoneNameDeveloper After updating Larawel to 5.6, users are required to enter each field in registration (all fields should not be asked).

Here is the code of RegisterController:

 protected function validator(array $data)
{

    return Validator::make($data, [
        'fname' => 'required|string|max:255',
        'lname' => 'required|string|max:255',
        'email' => 'required|string|email|max:255|unique:users',
        'password' => 'required|string|min:6|confirmed',
    ]);
}

protected function create(array $data)
{
    return User::create([
        'fname' => $data['fname'],
        'lname' => $data['lname'],
        'email' => $data['email'],
        'contact' => $data['contact'],
        'created_by' => $data['email'],
        'userrole' => Config::get('constants.ROLE_USER'),
        'password' => Hash::make($data['password']),
    ]);
}


 public function register(Request $request)
   {
        $validation = $this->validator($request->all());
        if ($validation->fails())  {
            return redirect()->back()->with(['errors'=>$validation->errors()->toArray()]);
        }
        else{
            $user = $this->create($request->all());
            Auth::login($user); 
            return redirect('/dashboard')->with(['message'=>'Account Successfully Created.']);
        }
   }

in your blade view :

@if (count($errors) > 0)
  @foreach ($errors->all() as $error)
    <p class="alert alert-danger alert-dismissible fade show" role="alert">{{ $error }}
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
    <span aria-hidden="true">&times;</span>
    </button>
  </p>
  @endforeach
@endif

@if (session()->has('message'))
    <p class="alert alert-success alert-dismissible fade show" role="alert">{{ session('message') }}
  <button type="button" class="close" data-dismiss="alert" aria-label="Close">
    <span aria-hidden="true">&times;</span>
  </button>
  </p>
@endif

The problem is that after i press the submit button nothing happens! @noeldiaz it have no diference, because the location of the form is the the laravel one and the actual web server error log) and see what it is recording? I am trying to use the validation for a registration page but not getting success, just displaying the same page and no data is getting inserted into the database neither on unique email nor on rep

After you click the register button, if you don't want to reload the page and instead redirect you to somewhere else, and also print a message, try something like this:

protected function create(array $data)
{
    $user = User::create([
        'fname' => $data['fname'],
        'lname' => $data['lname'],
        'email' => $data['email'],
        'contact' => $data['contact'],
        'created_by' => $data['email'],
        'userrole' => Config::get('constants.ROLE_USER'),
        'password' => Hash::make($data['password']),
    ]);

    session()->flash('message', 'Thank you for registering!');

    return redirect()->home();
}

Laravel provides several different approaches to validate your application's class PostController extends Controller { /** * Show the form to create a new blog post. Sometimes you may wish to stop running validation rules on an attribute after Again, notice that we did not have to explicitly bind the error messages to the  The most concise screencasts for the working developer, updated daily. There's no shortage of content at Laracasts. In fact, you could watch nonstop for days upon days, and still not see everything!

It is because you are returning User::create in your controller. You have to redirect to some page like homepage or other page.

If you have a homepage you can do like this in your controller.

protected function create(Request $request)
{
    $data = $request->all();
    $user =  User::create([
        'fname' => $data['fname'],
        'lname' => $data['lname'],
        'email' => $data['email'],
        'contact' => $data['contact'],
        'created_by' => $data['email'],
        'userrole' => Config::get('constants.ROLE_USER'),
        'password' => Hash::make($data['password']),
    ]);

    return redirect('home')->with('message', 'User registered!');;
}

and get message on homepage with this code,

@if (session('status'))
    <div class="alert alert-success">
        {{ session('status') }}
    </div>
@endif

If validation has failed, you may retrieve the error messages from the validator. If the incoming request was an AJAX request, no redirect will be generated. Form requests are custom request classes that contain validation logic. is called, meaning you do not need to clutter your controller with any validation logic. It has  Become a Laravel Partner. Laravel Partners are elite shops providing top-notch Laravel development and consulting. Each of our partners can help you craft a beautiful, well-architected project.

Master, 7.x, 6.x · 5.8 · 5.7 · 5.6 · 5.5 · 5.4 · 5.3 · 5.2 · 5.1 · 5.0 · 4.2 When you start a new Laravel project, error and exception handling is already configured for you. triggered by your application are logged and then rendered back to the user. exception handler contains an array of exception types that will not be logged. By default, Laravel includes an App\User Eloquent model in your app directory. This model may be used with the default Eloquent authentication driver. If your application is not using Eloquent, you may use the database authentication driver which uses the Laravel query builder. When building the database schema for the App\User model, make sure

By default, Laravel includes an App\User Eloquent model in your app directory. If your application is not using Eloquent, you may use the database you are ready to register and authenticate new users for your application! If you are using PHP FastCGI, HTTP Basic authentication may not work correctly out of the box. In this example, we used a traditional form to send data to the application. However, many applications use AJAX requests. When using the validate method during an AJAX request, Laravel will not generate a redirect response. Instead, Laravel generates a JSON response containing all of the validation errors. This JSON response will be sent with

There is a problem with displaying errors after a failing validation. Besides that, (re)filling forms with value="{{ old('name') }}" also does not work. [5.2] No errors and old input after failed validation when using database @laravel laravel locked and limited conversation to collaborators on Apr 24, 2016. Using Laravel notification to send email to the user about registration. To follow this article you should have existing or fresh laravel setup with version 5.6, as you will be seeing some codes samples only supporting this particular version and they may not be compatible with other older versions.

Comments
  • Several things you have to change. create controller should have public visibility. Use Request $request as argument instead array $data.
  • I hope this can help you: enter link description here
  • Found that adding @dump($errors) atop your register blade helps in figuring out what exactly the errors are. Saw this somewhere a while ago, used it and it helped me get ahead quickly.
  • In Laravel 5.6, I think @csrf is equivalent to {{ csrf_field }}.
  • exactly that is same.
  • @Shimul If you have solved this problem. Please accept the answer so others will know that this question is answered already.
  • Thanks for your alternate solution, but it is not the actual solution I want. So far I'm happy with Laravel default flow [ Registration & than auto login ]. It was an error on validation, which by default searching for name field but I extend name as fname and lname, that's why the error occurs.