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

createcontroller should have public visibility. UseRequest $requestas argument insteadarray $data.