1,105,295 Community Members

Laravel pass variable to redirect

Member Avatar
spowel4
Junior Poster in Training
72 posts since Jul 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

In Laravel 4, which I am just beginning to learn, I have this bit of logic in my controller:
$guid = Input::get('guid');. I know that part works because I can echo out the value successfully. I am trying to pass the $guid value to a view through a redirect like this: return Redirect::route('worktable1.show', $guid); but I keep getting an error "Undefined variable: guid" from the view. In the view itself I have this: {{ Form::hidden('guid', $guid) }}. I have done basically this same thing in other controllers/views without any problems but I can't figure out why this is working. Any suggestions?

Member Avatar
cereal
Posting Virtuoso
1,710 posts since Aug 2007
Reputation Points: 461 [?]
Q&As Helped to Solve: 345 [?]
Skill Endorsements: 44 [?]
 
0
 

Have you defined the variable in the method of the controller? For example:

public function getPage($guid)
{
    $data['guid'] = $guid;
    return View::make('page.form', $data);
}
Member Avatar
spowel4
Junior Poster in Training
72 posts since Jul 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks, I just tried your suggestion and it's still giving the undefined error. This is what I did in the controller:

$data['guid'] = $guid;
return Redirect::route('worktable1.show', $data);

And this is what I changed in the view: {{ Form::hidden('guid', $data) }}

Member Avatar
cereal
Posting Virtuoso
1,710 posts since Aug 2007
Reputation Points: 461 [?]
Q&As Helped to Solve: 345 [?]
Skill Endorsements: 44 [?]
 
0
 

This:

return Redirect::route('worktable1.show', $data);

Will redirect the request to another method. In your routes.php file you should have something similar to this:

Route::get('/page/{guid?}', array(
    'uses' => 'WorktableController@getPage',
    'as' => 'worktable1.show'
));

So, what you should show to us is the method that receives this datum, not the one from which you send it. Also don't change the view, $data in my example is an array to pass the variables to the view, so:

{{ Form::hidden('guid', $guid) }}

If for example you set more than one variable in the method controller:

public function getPage($guid)
{
    $data['guid'] = $guid;
    $data['msg'] = 'hello world';

    return View::make('page.form', $data);
}

Then in the view, you can do this:

{{ $guid }}

{{ $msg }}
Member Avatar
spowel4
Junior Poster in Training
72 posts since Jul 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
1
 

Thanks, I realize now that I should have been using View::make instead of a redirect.

Question Answered as of 2 Months Ago by cereal
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article