我已经查看了用户输入关于其个人资料详细信息(例如用户名,名字,姓氏等)的内容。上述情况只要注册并指向视图就会发生。只有当用户提供个人资料详情时,用户才会重定向到使用其他功能。用户还可以在将来更新配置文件的详细信息。laravel 5.2中DB的数据更新
这里,当用户想要更新配置文件详细信息更新页面中的详细信息时,我已经在注册后填写了详细信息。这里的问题是当我提交表单时,表示用户名已被占用。下面是这个视图
<div class="form-group{{ $errors->has('username') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">User Name</label>
<div class="col-md-6">
<input type="text" class="form-control" name="username" value="<?php echo \Auth::user()->username;?>">
@if ($errors->has('username'))
<span class="help-block">
<strong>{{ $errors->first('username') }}</strong>
</span>
@endif
</div>
</div>
的代码,但我没有创建一个数据库中的新行,但我更新现有列,它仍然抛出了同样的错误。这是我的控制器代码。
`public function prof_details(Request $request)
{
$post = $request->all();
$val=\Validator::make($request->all(),
[
'firstname' => 'required',
'lastname' => 'required',
'username' => 'required | unique:users',
'phone'=> 'required',
'nationality' => 'required',
'dobmonth' => 'required',
'dobyear' => 'required',
'dobday' => 'required',
'bio' => 'required',
'topics' => 'required',
]
);
if ($val ->fails())
{
return redirect()->back()->withErrors($val->errors());
}`
else
{
$data = array(
'firstname' => $post['firstname'] ,
'lastname' => $post['lastname'],
'username' => $post['username'],
'phone' => $post['phone'],
'nationality' => $nationality,
'dobmonth' => $post['dobmonth'],
'dobyear' => $post['dobyear'],
'dobday' => $post['dobday'],
'topics' => implode(',', $post['topics']),
'bio' => $post['bio'],
);
$updatedata = DB::table('users')->where('id',\Auth::user()->id)
->update($data);
if ($updatedata>0) {
return redirect('home');
}
else
{
return "something Went wrong";
}
这是一个正确的方法吗?或者哪一个是正确的方法呢? 在此先感谢。