how to edit the data when the admin verifies in laravel 5.6?
up vote
0
down vote
favorite
I have a problem while editing the data.
My condition is when the user updates the data, it must be the same until the admin approves his/her edit request.
Edit function
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..');
}
}
verify edit function
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>
so when the user updates the data the status must be changed to 4 at first and when the admin approves the request then the status must be 5 and data must be updated and the data shouldn't be updated until the admin approves it.
it's my problem.
php laravel-5
add a comment |
up vote
0
down vote
favorite
I have a problem while editing the data.
My condition is when the user updates the data, it must be the same until the admin approves his/her edit request.
Edit function
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..');
}
}
verify edit function
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>
so when the user updates the data the status must be changed to 4 at first and when the admin approves the request then the status must be 5 and data must be updated and the data shouldn't be updated until the admin approves it.
it's my problem.
php laravel-5
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a problem while editing the data.
My condition is when the user updates the data, it must be the same until the admin approves his/her edit request.
Edit function
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..');
}
}
verify edit function
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>
so when the user updates the data the status must be changed to 4 at first and when the admin approves the request then the status must be 5 and data must be updated and the data shouldn't be updated until the admin approves it.
it's my problem.
php laravel-5
I have a problem while editing the data.
My condition is when the user updates the data, it must be the same until the admin approves his/her edit request.
Edit function
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..');
}
}
verify edit function
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>
so when the user updates the data the status must be changed to 4 at first and when the admin approves the request then the status must be 5 and data must be updated and the data shouldn't be updated until the admin approves it.
it's my problem.
php laravel-5
php laravel-5
edited Nov 13 at 5:27
Gihan Saranga Siriwardhana
480113
480113
asked Nov 13 at 5:22
Prem Basnet
116
116
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274310%2fhow-to-edit-the-data-when-the-admin-verifies-in-laravel-5-6%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown