Php laravel在服务器端验证后重定向时还原我请求的值
当我尝试更新表单中的名称时,我正在使用laravel服务器端验证 输入错误的密码,它将重定向到同一页面并显示错误消息,但我尝试更新的名称已消失,并检索回旧名称 我的控制器是:Php laravel在服务器端验证后重定向时还原我请求的值,php,validation,laravel-5.4,Php,Validation,Laravel 5.4,当我尝试更新表单中的名称时,我正在使用laravel服务器端验证 输入错误的密码,它将重定向到同一页面并显示错误消息,但我尝试更新的名称已消失,并检索回旧名称 我的控制器是: public function profileupdate(Request $request,$id) { if(Auth::Check()) { $request_data = $request->All(); $valid
public function profileupdate(Request $request,$id)
{
if(Auth::Check())
{
$request_data = $request->All();
$validator = $this->validator($request_data);
if($validator->fails())
{
$this->throwValidationException($request, $validator);
}
else
{
$current_password = Auth::User()->password;
if(Hash::check($request_data['current-password'], $current_password))
{
$user_id = Auth::User()->id;
$admin = Admin::find($user_id);
$admin->update([
'name'=>$request['name'],
'job_title'=> $request['job_title'],
'email'=>$request['email'],
'phone_number'=>$request['phone_number'],
'password'=> Hash::make($request['current-password']),
]);
return redirect('/admin/profile')
->with('message', 'Admin Profile updated successfuly!');
}
else
{
return redirect('/admin/profile')
->with('password', 'Please enter correct password!');
}
}
}
else
{
return redirect()->to('/');
}
}
我的看法是:
<form action="{{ route('admin.profileupdate', Auth::user()->id) }}" method="get" class="form-horizontal" id="profile" name="profile">
{{csrf_field()}}
{{-- <input type="hidden" class="control-input" name="id" value="{{ Auth::user()->id }}"/> --}}
<div class="control-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label class="control-label">Name :</label>
<div class="controls">
<input type="text" class="control-input" name="name" value="{{ Auth::user()->name }}"/>
@if ($errors->has('name'))
<span class="help-inline">
<strong>{{ $errors->first('name') }}</strong>
</span>
@endif
</div>
</div>
<div class="control-group{{ $errors->has('job_title') ? ' has-error' : '' }}">
<label class="control-label">Role:</label>
<div class="controls">
<select class="control-select form-control" name="job_title" id="job_title" >
{{-- <option value="{{ Auth::user()->job_title }}">{{ Auth::user()->job_title }}</option> --}}
<option value="Admin" {{ (Auth::user()->job_title =="Admin") ? "selected" : "" }}>Admin</option>
<option value="Subadmin" {{ (Auth::user()->job_title =="Subadmin") ? "selected" : "" }}>Subadmin</option>
<option value="Superadmin" {{ (Auth::user()->job_title =="Superadmin") ? "selected" : "" }}>Superadmin</option>
</select>
@if ($errors->has('job_title'))
<span class="help-inline">
<strong>{{ $errors->first('job_title') }}</strong>
</span>
@endif </div>
</div>
<div class="control-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label class="control-label">Email:</label>
<div class="controls">
<input class="form-control" type="text" name="email" id="email" value="{{ Auth::user()->email }}" readonly>
@if ($errors->has('email'))
<span class="help-inline">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
<div class="control-group{{ $errors->has('phone_number') ? ' has-error' : '' }}">
<label class="control-label">Mobile Number :</label>
<div class="controls">
<input type="text" class="control-input" name="phone_number" id="phone_number" value="{{ Auth::user()->phone_number }}"/>
@if ($errors->has('phone_number'))
<span class="help-inline">
<strong>{{ $errors->first('phone_number') }}</strong>
</span>
@endif
</div>
</div>
<div class="control-group{{ $errors->has('current-password') ? ' has-error' : '' }}">
<label class="control-label"> Current Password:</label>
<div class="controls">
<input type="password" class="form-control" id="current-password" name="current-password" placeholder="Password">
@if(Session::has('password')) <span class="help-inline"> <strong>{{Session::get('password')}} </strong></span> @endif
@if ($errors->has('current-password'))
<span class="help-inline">
<strong>{{ $errors->first('current-password') }}</strong>
</span>
@endif
</div>
</div>
<div class="control-group">
<div class="controls">
<a href="{{ route('admin.password') }}">Change password</a>
</div>
</div>
<div class="form-actions">
<a href="{{ route('admin.dashboard') }}" class="btn btn-danger" >Cancel</a>
<button type="submit" class="btn btn-success">Update</button>
</div>
</form>
{{csrf_field()}}
{{-- --}}
姓名:
@如果($errors->has('name'))
{{$errors->first('name')}
@恩迪夫
角色:
{{--{Auth::user()->job_title}--}
工作职位==“管理员”)?“选定”:“}}>管理员
工作职位=“子管理员”)?“选定”:“}}>子管理员
职位=超级管理员“?“选定”:“}}>超级管理员
@如果($errors->has('job_title'))
{{$errors->first('job_title')}
@恩迪夫
电邮:
@如果($errors->has('email'))
{{$errors->first('email')}
@恩迪夫
手机号码:
@如果($errors->has('phone_number'))
{{$errors->first('phone_number')}
@恩迪夫
当前密码:
@if(Session::has('password')){{{Session::get('password')}}@endif
@如果($errors->has('current-password'))
{{$errors->first('current-password')}
@恩迪夫
更新
请帮助我如何获取输入的名称值。请输入正确的密码错误。控制器功能必须返回错误和输入数据- 从这里获取参考:
public function profileupdate(Request $request,$id)
{
if(Auth::Check())
{
$request_data = $request->All();
$validator = $this->validator($request_data);
if($validator->fails())
{
$this->throwValidationException($request, $validator);
}
else
{
$current_password = Auth::User()->password;
if(Hash::check($request_data['current-password'], $current_password))
{
$user_id = Auth::User()->id;
$admin = Admin::find($user_id);
$admin->update([
'name'=>$request['name'],
'job_title'=> $request['job_title'],
'email'=>$request['email'],
'phone_number'=>$request['phone_number'],
'password'=> Hash::make($request['current-password']),
]);
return redirect('/admin/profile')
->with('message', 'Admin Profile updated successfuly!');
}
else
{
// return redirect('/admin/profile')
// ->with('password', 'Please enter correct password!');
return Redirect::to('/admin/profile')->withInput()->withErrors($validation->messages());
}
}
}
else
{
return redirect()->to('/');
}
}