解決 Laravel 無法偵測到「使用者名稱」輸入的問題
<p>我是laravel的新手,我的程式碼之前是可以工作的,但是我把"name"改成了"username",然後如果我點擊提交,它會說它沒有預設值。 </p>
<pre class="brush:php;toolbar:false;">class UserSignup extends Controller {
public function register(Request $request) {
$validatedData = $request->validate([
'username' => ['required', 'string','max:255', Rule::unique('users')],
'email' => ['required', 'email', 'max:255', Rule::unique('users')],
'password' => 'required|min:8'
]);
$validatedData['password'] = bcrypt($validatedData['password']);
$user = User::create($validatedData);
return response()->json(['message' => 'User created successfully!', 'user' => $user]);
}
}</pre>
<p>我嘗試將"name"改成"username"如下所示</p>
<pre class="brush:php;toolbar:false;">$validatedData = $request->validate([
'username' => ['required', 'string','max:255', Rule::unique('users')],
'email' => ['required', 'email', 'max:255', Rule::unique('users')],
'password' => 'required|min:8'
]);</pre>
<p>點擊提交後會出現錯誤,說它沒有預設值。 </p>
<p>我只想把'username'放入資料庫。 </p>