当前位置: 首页 > 知识库问答 >
问题:

Laravel 5.2错误消息未显示

曹奇文
2023-03-14

我已经找到了一些答案,但我的问题仍然没有解决。

我刚刚制作了一个新的应用程序,发现注册页面上的错误消息根本没有显示出来。以下是我在本网站上找到的一些答案:

  1. 只需删除,'中间件'=

\照明\会话\中间件\开始会话::class,\照明\视图\中间件\ShareErrs From会话::class,

从受保护的$middlewareGroup到karnel中受保护的$middleware中间件。php页面

(感谢Atiqur)

当我点击注册按钮时,致命错误弹出:致命错误:调用字符串上的成员函数first()(视图:C:\xampp\htdocs\laravel\资源\视图\auth\register.blade.php)

这里有一些我的代码供参考。请帮忙。

路线。php

Route::get('/', function () {
    return view('welcome');
});

Route::group(['prefix' => 'user'], function () {

    Route::get('/', 'UserController@index');

    Route::post('/', 'UserController@update');

    Route::post('/edit', 'UserController@edit');
});


Route::auth();

Route::get('/home', 'HomeController@index');

Route::get('/test', 'TestController@index');

kernel.php

<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{
    /**
     * The application's global HTTP middleware stack.
     *
     * These middleware are run during every request to your application.
     *
     * @var array
     */
    protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
    ];

    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
        ],

        'api' => [
            'throttle:60,1',
        ],
    ];
/**
 * The application's route middleware.
 *
 * These middleware may be assigned to groups or used individually.
 *
 * @var array
 */
protected $routeMiddleware = [
    'auth' => \App\Http\Middleware\Authenticate::class,
    'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    'can' => \Illuminate\Foundation\Http\Middleware\Authorize::class,
    'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
    'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
];

}

授权控制器。php

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */

    use AuthenticatesAndRegistersUsers, ThrottlesLogins;

    /**
     * Where to redirect users after login / registration.
     *
     * @var string
     */
    protected $redirectTo = '/';

    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware($this->guestMiddleware(), ['except' => 'logout']);
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|unique:users|min:3|max:20|alpha_dash',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|min:8|confirmed',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }
}

注册的。刀身php

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <div class="panel panel-default">
                <div class="panel-heading">Register</div>
                <div class="panel-body">
                    <form class="form-horizontal" role="form" method="POST" action="{{ url('/register') }}">
                        {!! csrf_field() !!}

                        <div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
                            <label class="col-md-4 control-label">Name</label>

                            <div class="col-md-6">
                                <input type="text" class="form-control" name="name" value="{{ old('name') }}">

                                @if (count($errors) > 0)
                                    <div class="alert alert-danger">
                                        <ul>
                                            @foreach ($errors->all() as $error)
                                                <li>{{ $error->first('name') }}</li>
                                            @endforeach
                                        </ul>
                                    </div>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
                            <label class="col-md-4 control-label">E-Mail Address</label>

                            <div class="col-md-6">
                                <input type="email" class="form-control" name="email" value="{{ old('email') }}">

                                @if (count($errors) > 0)
                                    <div class="alert alert-danger">
                                        <ul>
                                            @foreach ($errors->all() as $error)
                                                <li>{{ $error->first('email') }}</li>
                                            @endforeach
                                        </ul>
                                    </div>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
                            <label class="col-md-4 control-label">Password</label>

                            <div class="col-md-6">
                                <input type="password" class="form-control" name="password">

                                @if (count($errors) > 0)
                                    <div class="alert alert-danger">
                                        <ul>
                                            @foreach ($errors->all() as $error)
                                                <li>{{ $error->first('password') }}</li>
                                            @endforeach
                                        </ul>
                                    </div>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}">
                            <label class="col-md-4 control-label">Confirm Password</label>

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

                                @if (count($errors) > 0)
                                    <div class="alert alert-danger">
                                        <ul>
                                            @foreach ($errors->all() as $error)
                                                <li>{{ $errors->first('password_confirmation') }}</li>
                                            @endforeach
                                        </ul>
                                    </div>
                                @endif
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                <button type="submit" class="btn btn-primary">
                                    <i class="fa fa-btn fa-user"></i>Register
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

php artisan-v

Laravel Framework version 5.2.35

共有2个答案

华炜
2023-03-14

将此代码插入寄存器。刀身php

@if ($errors->any())
<div class="alert alert-danger">
    <ul>
        @foreach ($errors->all() as $error)
            <li>{{ $error }}</li>
        @endforeach
    </ul>
</div>
@endif
谢典
2023-03-14

试试这个在刀片

 <div class=" form-group has-feedback{{ $errors->has('name') ? ' has-error' : '' }}">
            <input type="text" class="form-control" name="name" value="{{ old('name') }}"
                   placeholder="Full Name">

            @if ($errors->has('name'))
                <span class="help-block">
                    <strong>{{ $errors->first('name') }}</strong>
                </span>
            @endif
        </div>`<div class="form-group has-feedback{{ $errors->has('email') ? ' has-error' : '' }}">
            <input type="email" class="form-control" name="email" value="{{ old('email') }}"
                   placeholder="Email">

            @if ($errors->has('email'))
                <span class="help-block">
                    <strong>{{ $errors->first('email') }}</strong>
                </span>
            @endif
        </div>`<div class="col-md-6">
                <div class="form-group has-feedback{{ $errors->has('password') ? ' has-error' : '' }}">
                    <input type="password" class="form-control" name="password" placeholder="Password">

                    @if ($errors->has('password'))
                        <span class="help-block">
                    <strong>{{ $errors->first('password') }}</strong>
                </span>
                    @endif
                </div>
            </div>
 类似资料:
  • 我正在将Spring jsp应用程序迁移到Thymeleaf,但在显示表单错误时遇到问题。 当我尝试使用以下方法显示错误时: 它不会显示任何错误。 我尝试了http://www.thymeleaf.org/doc/html/thymeleaf-spring3.html#validation-and-error-messages#validation-and-error-messages上的各种替代

  • 我使用的是关于这个链接的教程: http://www.mkyong.com/spring-security/display-custom-error-message-in-spring-security/ 在登录表单上显示一个自定义错误消息,我在开始时就得到了它。但是在为自定义失败身份验证器处理程序声明authentication-failure-handler-ref=“myautherrorh

  • 问题内容: 我安装了XAMPP 1.7.4(使用PHP 5.3.5),问题是PHP不显示任何错误消息。例如,如果我使用不带参数的MYSQL连接,PHP将不会抱怨必填字段。 为什么是这样? 如何配置PHP以显示错误? 问题答案: 要在脚本级别启用错误,请在脚本顶部添加: 或者,如果它 不是 生产站点,而仅仅是开发/测试站点,则可以在php.ini中打开错误报告。搜索以下设置:

  • 我在AngularJs中添加了ng repeat部分。我添加了一个必需的字段验证器。但是,当所有字段都清空时,页面高度会增加,因为会显示span标记数据。。是否可以在描述错误的ng repeat部分之后仅显示一条错误消息。当前UI代码如下: 如何在ng repeat部分之后只添加一条错误消息,以在AngularJs中描述所需的数据?谢谢