Laravel 5输入旧为空 [英] Laravel 5 input old is empty

查看:62
本文介绍了Laravel 5输入旧为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的路线在这里

My routes is here

Route::get('sign-up', ['as' => 'signUp', 'uses' => 'UserController@signUpGet']);
Route::post('sign-up', ['as' => 'signUpPost', 'uses' => 'UserController@signUpPost']);

控制器

return redirect('signUp')->withInput();

然后查看

    <form role="form" method="POST" action="{{route('signUpPost')}}"> 
        <input type="text" class="form-control" name="username" value="{{ old('username') }}">
</form>

{{old()}}函数返回空值.
编辑

The {{old()}} function return empty value.
EDIT
I took

NotFoundHttpException in RouteCollection.php line 145:

推荐答案

您的问题似乎根本没有真正提交用户名:

Your problem looks like you are not actually submitting the username in the first place:

<form role="form" method="POST" action="{{route('signUpPost')}}"> 
        <input type="text" class="form-control" name="username" value="{{ old('username') }}">
</form>

表单内没有提交"按钮.如果您在表格外提交-那么username将不包括在内.

There is no 'submit' button inside the form. If you submit outside the form - then the username will not be included.

在表单内添加提交"按钮-然后重试

Add the submit button inside your form - then try again

<form role="form" method="POST" action="{{route('signUpPost')}}"> 
        <input type="text" class="form-control" name="username" value="{{ old('username') }}">
        <input type="submit" value="Submit">
</form>

编辑-您的控制器也是错误的.应该是这样:

Edit - also your controller is wrong. It should be this:

 return redirect()->route('signUp')->withInput();

这篇关于Laravel 5输入旧为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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