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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。