doutou1922 2018-11-13 05:22
浏览 19

管理员在laravel 5.6中验证时如何编辑数据?

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值