Page 1 of 1

How to pass data from anchor tag in laravel?

Posted: Wed Dec 14, 2016 8:37 am
by gautamz07
I currently have a form in laravel on whos submission the following methods run:

Code: Select all

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:

Code: Select all

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:

Code: Select all

@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:

Code: Select all

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:

Code: Select all

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.
Thank you.
Gautam.

Re: How to pass data from anchor tag in laravel?

Posted: Wed Dec 14, 2016 8:56 am
by Celauran
What value does that extra request provide? As it sounds like it's just for display, could you not print out the session data in a hidden div and have the link toggle visibility?

Re: How to pass data from anchor tag in laravel?

Posted: Wed Dec 14, 2016 12:32 pm
by gautamz07
@celauran ! yes for production that would be a much better method , but as of now i am just doing this for educational purposes :P

So i now have the following code for the anchor:

Code: Select all

@if(Session::has('quality-data'))
	<a href="{{ url('showQualityResult' , compact(Session::get('quality-data'))) }}">Submited Quality Check</a>
@endif
The following in my routes file:

Code: Select all

Route::get('/showQualityResult', 'QualityCheckController@showQualityResult');
and i have the following in my controlller:

Code: Select all

public function showQualityResult($qualityData) {
		return $qualityData;
		// return view('quality-result' , compact($qualityData));
	}
But i get the following error:

http://imgur.com/PdqbR4y

i guess the error is because the URL method is not passing the variable to the controller method . :(