Laravel 5.6-注册表不起作用并且没有显示任何错误 [英] Laravel 5.6 - Registration Form is not working and does not show any error

查看:64
本文介绍了Laravel 5.6-注册表不起作用并且没有显示任何错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我最近的一个项目中,自定义注册表格不起作用.当我单击注册按钮时,它将重新加载注册表单,不显示任何错误,并且没有数据插入数据库.这是注册表的外观:

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:

这是迁移文件的代码:

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();
    });
}

这是用户模型的代码:

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

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

这是 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']),
    ]);
}

这是 constants.php 的代码,该代码位于 config 文件夹中:

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

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

最后,这是 register.blade.php 文件的代码:

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?

  • 谢谢

推荐答案

可能是因为您拥有 @csrf 而不是 {{csrf_field}} ,所以CSRF令牌不会被发布.

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

您还可以将其添加到Controller动作中,以查看发布的内容:

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

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

但是请注意,可能会对操作执行任何验证的任何 Request

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

这篇关于Laravel 5.6-注册表不起作用并且没有显示任何错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆