0
我有一個問題,我有三個字段,三個中的兩個發佈到數據庫。我會在下面發佈我的代碼,看看你能否幫助我。輸入數據沒有發佈到數據庫
如果您想的完整代碼預覽它,可以發現: http://github.com/mikerodham/chatty
我下面由CodeCourse/PHPAcademy社會網絡教程,這僅僅是一個奇怪的錯誤,我偶然發現。
是的我檢查數據庫中的用戶名字段是否拼寫正確!
VIEW
<form class="form-vertical" role="form" method="post" action="{{ route('auth.signup') }}">
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="control-label">Your email address</label>
<input type="text" name="email" class="form-control" id="email" value="{{ Request::old('email') ?: '' }}">
@if ($errors->has('email'))
<span class="help-block">{{ $errors->first('email') }}</span>
@endif
</div>
<div class="form-group{{ $errors->has('username') ? ' has-error' : '' }}">
<label for="username" class="control-label">Your desired username</label>
<input type="text" name="username" class="form-control" id="username" value="{{ Request::old('username') ?: '' }}">
@if ($errors->has('username'))
<span class="help-block">{{ $errors->first('username') }}</span>
@endif
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="control-label">Your desired password</label>
<input type="password" name="password" class="form-control" id="password" value="">
@if ($errors->has('password'))
<span class="help-block">{{ $errors->first('password') }}</span>
@endif
</div>
<div class="form-group">
<button type="submit" class="btn btn-default">Sign up</button>
</div>
<input type="hidden" name="_token" value="{{ Session::token() }}">
</form>
控制器
public function postSignup(Request $request)
{
$this->validate($request, [
'email' => 'required|unique:users|email|max:255',
'username' => 'required|unique:users|alpha_dash|max:20',
'password' => 'required|min:6',
]);
User::create([
'email' => $request->input('email'),
'username' => $request->input('username'),
'password' => bcrypt($request->input('password')),
]);
return redirect()->route('home')->with('info', 'Your account has been created and you can now sign in!');
}
你確定你的'username'字段聲明爲可以在你的雄辯模型中填充嗎? –
顯然我只是把'名字'這已被修復,並可以確認它的工作!謝謝! :d –