gpt4 book ai didi

mysql - 不将用户数据保存到 laravel 5.6 中的用户表

转载 作者:行者123 更新时间:2023-12-01 00:35:33 25 4
gpt4 key购买 nike

我打算在 laravel 5.6 中向 users 表插入新的数据记录。这是我的用户 Controller ,

public function store(Request $request)
{
$this->validate($request,[
'name' => 'required|max:255',
'userlevel' => 'required',
'email' => 'required|email|unique:users',
]);
$user = new User();
$user->name = $request->input('name');
$user->uservalue = $request->input('uservalue');
$user->email = $request->input('email');
$user->password = $request->input(bcrypt($data['password']));
$user->save();
return redirect()->route('users.show', $user->id);
}

Blade 文件是,

<form action="{{route('users.store')}}" method="POST">
{{csrf_field()}}
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Enter Name">
</div>

<div class="form-group">
<label for="exampleFormControlSelect1">User Level</label>
<select class="form-control" id="uservalue" name="uservalue">
<option>0</option>
<option>2</option>
<option>1</option>

</select>
</div>

<div class="form-group">
<label for="email">Email</label>
<input type="text" class="form-control" id="email" name="email" placeholder="Enter Email">
</div>

<div class="form-group">
<label for="password">Password</label>
<input type="text" class="form-control" id="password" name="password" placeholder="Enter Password">

</div>
<button type="submit" class="btn btn-primary">Create User</button>
</form>
</div>

路线是,

Route::resource('/users','UserController');

但是当我点击提交按钮时,数据没有保存到用户表中。没有出现任何错误信息。只刷新页面。如何解决这个问题?

最佳答案

public function store(Request $request)
{
$this->validate($request,[
'name' => 'required|max:255',
'uservalue' => 'required',
'email' => 'required|email|unique:users',
]);
$user = new User();
$user->name = $request->input('name');
$user->uservalue = $request->input('uservalue');
$user->email = $request->input('email');
$user->password = $request->input(bcrypt($data['password']));
$user->save();
return redirect()->route('users.show', $user->id);
}

请将用户级别更改为用户值

关于mysql - 不将用户数据保存到 laravel 5.6 中的用户表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51645745/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com