我有AuthController
use Illuminate\Http\Request;
use ConnectIn\Http\Requests;
class AuthController extends Controller
{
public function getSignUp()
{
return view('auth.signup');
}
public function postSignUp(Request $request)
{
$this -> validate($request, [
'username' => 'required|unique:users|alpha_dash|max:255',
'useremail' => 'required|unique:users|email|max:255',
'userpassword' => 'required|min:8'
]);
//dd("all OK");
}
}
我的路线是
Route::get('/', [
'uses' => '\App\Http\Controllers\AuthController@getSignup',
'as' => 'auth.signup',
]);
Route::post('/', [
'uses' => '\App\Http\Controllers\AuthController@postSignUp',
]);
signup.blade.php是
@extends ('templates.default')
@section('register')
<div id="login-page" class="row">
<form class="login-form" method="post" action="{{route('auth.signup')}}">
<div class="row">
<div class="input-field col s12 center">
<h4>Register</h4>
<p class="center">Join to our community now !</p>
</div>
</div>
<div class="row margin">
<div class="input-field col s12">
<i class="mdi-social-person-outline prefix"></i>
<input id="username" name="username" type="text">
<label for="username" class="center-align">Username</label>
@if($errors->has('username'))
<div class="error">{{$errors->first('username')}}</div>
@endif
</div>
</div>
<div class="row margin">
<div class="input-field col s12">
<i class="mdi-communication-email prefix"></i>
<input id="email" name="useremail" type="email">
<label for="email" class="center-align">Email</label>
@if($errors->has('email'))
<div class="error">{{$errors->first('email')}}</div>
@endif
</div>
</div>
<div class="row margin">
<div class="input-field col s12">
<i class="mdi-action-lock-outline prefix"></i>
<input id="password" name="userpassword" type="password">
<label for="password">Password</label>
@if($errors->has('userpassword'))
<div class="error">{{$errors->first('userpassword')}}</div>
@endif
</div>
</div>
<div class="row margin">
<div class="input-field col s12">
<i class="mdi-action-lock-outline prefix"></i>
<input id="password-again" type="password">
<label for="password-again">Password again</label>
</div>
</div>
<input type="hidden" name="_token" value="{{ Session::token()}}">
<div class="row">
<div class="input-field col s12">
<input type="submit" value="Regiter Now" class="btn waves-effect waves-light col s12"/>
</div>
</div>
</form>
</div>
@stop
此时我没有收到任何错误,但无法提交表单,我的验证根本不起作用,我在那里错过了一些东西。
答案 0 :(得分:0)
In the postSignUp
function, change your code to:
$this->validate($request->all(), [
'username' => 'required|unique:users|alpha_dash|max:255',
'useremail' => 'required|unique:users|email|max:255',
'userpassword' => 'required|min:8'
]);