php - Laravel 5.6 - 注册表不工作且未显示任何错误

标签 php laravel laravel-5.6

在我最近的一个项目中,自定义注册表不管用。当我点击注册按钮时,它会重新加载注册表,不打印任何错误并且没有数据插入到数据库中。这是注册表的外观:

enter image description here

这是迁移文件代码:

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',
];

这是的代码注册 Controller :
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']),
    ]);
}

这是的代码常量.php , 里面是 配置文件夹:
<?php
    return array(
        'ROLE_ADMIN' => 'ROLE_ADMIN',
        'ROLE_USER' => 'ROLE_USER'
    );

最后,这里是的代码register.blade.php 文件:
@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

这是我的问题的简短剪辑:Video Clips

那么,谁能帮我弄清楚,实际问题是什么?我该如何解决这个问题?
  • 感谢
  • 最佳答案

    可能是因为你有@csrf而不是 {{ csrf_field }}所以CSRF token 不会被发布。

    另外,为了测试,您可以尝试将其添加到您的 Blade 中:

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

    您还可以将其添加到您的 Controller 操作中以准确查看发布的内容:
    dd(request()->all());
    

    但请注意任何 Request可能正在对操作进行任何验证的 s

    关于php - Laravel 5.6 - 注册表不工作且未显示任何错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49998255/

    相关文章:

    php - 如何从 laravel 中的数据库中选择最后一行

    php - 如何从 .phpcs.xml 中的 PHP Code Sniffer 检查中排除某些目录以外的所有内容?

    php - Dropzone 在后端 Laravel 中没有有效的 MIME 类型?

    php - php如何转换 bool 变量?

    Laravel API resourceCollection 使用数组而不是模型

    php - 我们可以在 controller laravel 中使用 helper 吗?

    Laravel 向路由组添加自定义中间件

    php - 拉维尔 5.6 : Customise a paginated resource collection meta and links attributes

    PHP 数据库编程

    javascript - 如何使用 Vue js 从 API 数据创建搜索过滤器?