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条)

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题