编辑数据时出现问题。 我的条件是用户更新数据时,在管理员批准其编辑请求之前,该数据必须相同。
编辑功能
public function editNotice(Request $request,$id=null){
if(Session::has('idSession')){
if($request->isMethod('post')){
$data = $request->all();
$this->validate($request, [
'death_name' => 'required',
'file_name' => 'required',
'file' => 'mimes:pdf|max:2048',
'description' => 'required',
'published_date' => 'required|date_format:Y-m-d'
],
[
'death_name.required'=> 'Late Person Name is required',
'file_name.required'=> 'File Name is required',
'file.mimes'=> 'File must be in pdf format.',
'file.max'=> 'File must be less than 2MB',
'description.required' => 'Description is required',
'published_date.date_format' => 'Published Date must be in Y-m-d (2018-09-23) format'
]);
if($data['status'] == 5){
if($request->has('file')){
$file = Input::file('file');
if($file->isValid()){
$file = $request->file('file');
$destination_path = public_path().'/death_notice_files';
$date = date('Y-m-d_H-i-s');
$extension = $file->getClientOriginalExtension();
$fileExtension = strtolower($extension);
// $files = $file->getClientOriginalName();
$userID = Session::get('idSession');
$files = 'death_notice_'.$userID.'-'.$id.'_'.$date;
$file_name = pathinfo($files, PATHINFO_FILENAME);
$fileWithExtension = $file_name.'.'.$fileExtension;
// $fileName = $fileWithExtension;
$finalFileName = str_replace(' ', '_', $fileWithExtension);
// $deathNotice->file = $finalFileName;
$file->move($destination_path,$finalFileName);
}
} else {
$finalFileName = $data['current_file'];
}
DB::table('death_notice')->where(['id'=>$id])->update(['name' => $data['death_name'],'description' => $data['description'],'published_date'=>$data['published_date'],'ending_date'=>$data['ending_date'],'file_name'=>$data['file_name'],'file'=> $finalFileName,'status'=> 5]);
return redirect('/user/view-notice')->with('flash_message_success','Notice Updated Successfully..');
}
//4 is edit pending status
DB::table('death_notice')->where(['id'=>$id])->update(['status'=> 4]);
return redirect('/user/view-notice')->with('flash_message_success','Notice Update Request Sent Successfully..');
}
$noticeDetails = DB::table('death_notice')->where(['id'=>$id])->first();
return view('death_notice.notice.edit_notice')->with(compact('noticeDetails'));
} else {
return redirect('/user')->with('flash_message_error','Please Login First to access..');
}
}
验证编辑功能
public function verifyEditNotice(Request $request,$id=null){
if(empty($data['status'])){
//5 is edited status
DB::table('death_notice')->where(['id'=>$id])->update(['status'=> 5]);
DeathNoticeController::editNotice($request,$id);
}
return redirect('/user/view-all-notice')->with('flash_message_success','Notice Updated Successfully...');
}
edit_notice.blade.php
<form action="{{ url('/user/edit-notice/'.$noticeDetails->id) }}" method="post" enctype="multipart/form-data" class="form-horizontal" name="edit_death_notice" id="edit_death_notice" novalidate="novalidate"> {{ csrf_field() }}
<div class="control-group">
<label class="control-label">Late Person Name <span style="color:red;">*</span></label>
<div class="controls">
<input type="text" id="death_name" name="death_name" placeholder="Enter Name" value=" {{ $noticeDetails->name }} ">
</div>
</div>
<div class="control-group">
<label class="control-label">File Name <span style="color:red;">*</span></label>
<div class="controls">
<input type="text" id="file_name" name="file_name" placeholder="Enter File Name" value=" {{ $noticeDetails->file_name }} ">
</div>
</div>
<div class="control-group">
<label class="control-label">File <span style="color:red;">*</span></label>
<div class="controls">
<input type="file" name="file" id="file" />
<input type="hidden" name="current_file" value=" {{ $noticeDetails->file }} "> <span> {{ $noticeDetails->file }} </span><br><span style="color:red;" id="file_error">File must be less than 2MB </span>
</div>
</div>
<div class="control-group">
<label class="control-label">Description <span style="color:red;">*</span></label>
<div class="controls">
<textarea class="span6" name="description" id="description"> {{ $noticeDetails->description }}</textarea>
</div>
</div>
<div class="control-group">
<label class="control-label">Published Date <span style="color:red;">*</span></label>
<div class="controls">
<input type="text" id="published_date" name="published_date" data-date="01-01-2017" data-date-format="yyyy-mm-dd" class="datepicker span11" value=" {{ $noticeDetails->published_date }}">
<?php $duration = DB::table('migrations')->first();?>
<input type="hidden" id="duration" name="duration" value="{{ $duration->notice_duration }}">
</div>
</div>
<div class="control-group">
<label class="control-label">Ending Date</label>
<div class="controls">
<input type="text" id="ending_date" name="ending_date" readonly="readonly" value="{{ $noticeDetails->ending_date }}">
</div>
</div>
<div class="control-group" style="display: none;">
<div class="controls">
<input type="text" readonly="readonly" id="status" name="status" value="{{ $noticeDetails->status }}">
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-success">Update</button>
</div>
</form>
因此,当用户更新数据时,首先必须将状态更改为4,而当管理员批准请求时,状态必须为5并且数据必须更新,并且在管理员批准之前不应更新数据。 这是我的问题。