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

报告相同问题?