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?

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);
}

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

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 }}

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.