donglue1886 2016-12-14 14:03
浏览 40
已采纳

如何从laravel中的锚标签传递数据?

I currently have a form in laravel on whos submission the following methods run:

public function validateSave() {
        $qualitycheck = new QualityCheck();
        $qualitycheck['site-name'] = Request::input('site-name');
        $qualitycheck['favicon'] = Request::has('favicon');
        $qualitycheck['title'] = Request::has('title');
        $qualitycheck['image-optimization'] = Request::has('image-optimization');
        $qualitycheck->save();
        Session::flash('quality-data', $qualitycheck);
        return redirect('/');
    }

So i have the below line that passes the data to the next page:

Session::flash('quality-data', $qualitycheck);

But what i would really want to do is, when the form is submitted, i would really just want to show a link on the next page , which will be coded like so:

@if(Session::has('quality-data'))
        <a href="">Submited Quality Check</a>
@endif

Now on click on the link , i would like to show a view with all the data that the user submitted in the form , How do i do this ? I.E. How do i pass the data form from the <a> to the view that will show up when clicked on the <a> ??

So just to put things into perspective, this is how it works now:

STEP-1 :: User submits form , data is flashed to next page.  
STEP-2 :: Data user submits is shown on this page.

How i want it to work is:

STEP-1 :: User submits form , data is flashed to next page.
STEP-2 :: A link is shown to the user(Only if user clicks on the link we move to the next step).
STEP-3 :: Data user submited in first step is shown on this page.
  • 写回答

2条回答 默认 最新

  • dsfgds4215 2016-12-14 14:42
    关注

    Next time you code, please follow the below coding practices.

    1. Prefer using create() function of model.
    2. Put all your request data that is to be used in one variable (like $input)
    3. Prefer using route names like route('route.name') instead of strings inside redirection() function.

    Please replace your function with

    public function validateSave() {
      $inputs = [
        'site-name' => request()->get('site_name'),
        'favicon' => request()->has('facvicon'),
        'title' => request()->has('title'),
        'image-optimization' => request()->has('image-optimization')
      ]);
    
      $qualityCheck = QualityCheck::create($inputs);
    
      $flashMessage = '<a href=' . route('quality.check.show', $qualityCheck) . '>Submitted Quality Check</a>'
    
      Session::flash('quality-data', $flashMessage);
    
      return redirect(route('home.index'));
    }
    

    And ensure you have something like this in your routes file.

    Route::get('quality-check/{id}', 'QualityCheckController')->name('quality.check.show');
    

    Let me know if something doesn't work...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大