我一直在Laravel为自己的学习目的建立一个迷你社交网络。当我想更新我制作的个人资料中的一些数据时,我遇到了问题。 8是我的身份。
这是我用于更新的表单:
{!! Form::open(array('route' => ['edit_user',$user-> id],'id' => 'form_sample_1','class'=>'form-horizontal','novalidate' => 'novalidate','role' => 'form')) !!}
{!! csrf_field() !!}
<div class="form-body">
<div class="alert alert-danger display-hide">
<button class="close" data-close="alert"></button> You have some form errors. Please check below. </div>
<div class="form-group">
<label class="control-label col-md-3">Name
<span class="required" aria-required="true"> * </span>
</label>
<div class="col-md-4">
<input type="text" name="name" data-required="1" value="{{$user->name}}" class="form-control">
@if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">Email
<span class="required" aria-required="true"> * </span>
</label>
<div class="col-md-4">
<input name="email" type="text" class="form-control" value="{{$user->email}}" >
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
</div>
<div class="form-actions">
<div class="row">
<div class="col-md-offset-3 col-md-9">
<button type="submit" class="btn green">Submit</button>
<button type="button" class="btn grey-salsa btn-outline">Cancel</button>
</div>
</div>
</div>
{!! Form::close() !!}
这是功能:
public function update(Request $request, $id)
{
$this->validate($request, array(
'name'=>'required|max:255',
'email'=>'required|unique:users|max:255'
));
$user= User::find($id);
//echo $user->name;
//echo $request->name;
$user->name = $request->name;
$user->user_modify_id = Auth::user()->id;
if($user->email != $request->email)
{
$user->email = $request->email;
}
if($user->save())
{
return redirect('user_profile',$id)->with('success', sprintf('User: "%s" successfully saved.', $user->name));
}else if ($validation->fails())
{ echo 'undone';
return redirect('user_profile',$id.'#tab_1-1');
}
}
这是路线文件中的路线:
Route::post('edit_user/{user}',array('as' => 'edit_user','middleware' => 'auth','uses' => 'UserController@update'));
答案 0 :(得分:0)
重定向功能的第二个参数是状态代码。
尝试使用路径助手功能来创建正确的URL:
https://laravel.com/docs/5.2/helpers#method-route
return redirect(route('user_profile',$id.'#tab_1-1'));