本文介绍了Laravel 5 withInput老总是空的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel 5构建一个简单的登录表单,并且在发生某些错误时,我想默认情况下填写一些输入.我的路由器按照给定的方式调用这些功能

I'm building a simple login form using Laravel 5 and I would like to fill some inputs by default when some error occurred. My router is calling these functions as given

Route::get('/login','AuthController@login');
Route::post('/login','AuthController@do_login');

我的控制器如下所示

namespace App\Http\Controllers;
use App;
use App\Models\User;
use Request;
use Illuminate\Support\Facades\Redirect;

class AuthController extends Controller {

   function login()
   {
       if(User::check())
       {
           /*User is logged, then cannot login*/
           return Redirect::back();
       }
       else
       {
           return view('auth.login');
       }
   }
    function do_login()
    {
        return view('auth.login')->withInput(Request::except("password"));
    }

}

PhpStorm强调了withInput的含义,说在Illuminate \ View \ View中找不到它的实现.在我看来,我有以下几点:

Noticing that withInput is being underlined by PhpStorm saying that can't find it's implementation in Illuminate\View\View.Inside my view, i have the following:

            {!! Form::open() !!}
            <div class="form-group">
                {!! Form::text('email', Input::old('email'), array('placeholder' => Lang::get('auth.email'), 'class' => 'form-control')) !!}
            </div>
            <div class="form-group">
                {!! Form::password('password', array('placeholder' => Lang::get('auth.password'),'class'=>'form-control')) !!}
            </div>
            <div class="form-group">
                <button class="btn btn-primary btn-block">@lang('auth.signin')</button>
                <span class="pull-right"><a href="/{{App::getLocale()}}/register">@lang('auth.register')</a></span>
            </div>
        <input type="email" class="form-control" name="email" value="{{ old('email') }}">
        {!! Form::close() !!}

我在这里想念什么?这可以在Laravel 5中完成吗?非常感谢您的宝贵时间!

What am I missing here? This can be done in Laravel 5 ?Many thanks for your time!

推荐答案

withInput()用于在重定向期间保留输入.

withInput() is for preserving the input during redirects.

如果正在执行return view(),则不必(也不可能)调用它.

It is not necessary (nor possible) to call it if you're doing a return view().

您可能会考虑让do_login执行return redirect()->back()->withInput(Request::except("password"));来正确实现 Post/Redirect/Get .

You might consider having your do_login do return redirect()->back()->withInput(Request::except("password")); though, to properly implement Post/Redirect/Get.

这篇关于Laravel 5 withInput老总是空的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 12:45