Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I'm really new to Laravel, and I'm not sure that I know what I'm doing. I have a form in my main view. I'm passing the input to a controller, and I want the data to be displayed in another view. I can't seem to get the array from the controller to the second view. I keep getting 500 hphp_invoke. Here's where I'm passing the array from the controller to view2.

public function formSubmit()
{
    if (Input::post())
    {
        $name = Input::get('name');
        $age = Input::get('age');
        $things = array($name, $age);
        return View::make('view2', array('things'=>$things));
    }
}

view1.blade.php

{{ Form::open(array('action' => 'controller@formSubmit')) }}
    <p>{{ Form::label('Name') }}
    {{ $name = Form::text('name') }}</p>
    <p>{{ Form::label('Age') }}
    {{ $age = Form::text('age') }}</p>
    <p>{{ Form::submit('Submit') }}</p>
{{ Form::close() }}

My view2.php file is really simple.

<?php
    echo $name;
    echo $age;
?>

Then in routes.php

Route::get('/', function()
{
    return View::make('view1');
});
Route::post('view2', 'controller@formSubmit');

Why isn't this working?

share|improve this question

try with()

$data = array(
    'name'  => $name,
    'age' => $age
);

return View::make('view2')->with($data);

on view get :- echo $data['name']; echo $data['age'];

or

return View::make('view2')->with(array('name' =>$name, 'age' => $age));

get on view :-

echo $name;
echo $age;

For more Follow here

share|improve this answer
    
Thanks for your help. That doesn't seem to be working though. Could it be the route that I have? It's Route::post('view2','controller@formSubmit'); Is that wrong? – porcupine92 Oct 8 '14 at 7:32
    
I added more of my code. Nothing that I change seems to be working. Do you see anything else wrong with what I have? – porcupine92 Oct 8 '14 at 7:53

You need to use:

return View::make('view2')->with(['name' => $name, 'age' => $age]);

to use

$name and $age in your template

share|improve this answer

Since $things is already an array so you may use following approach but make the array associative:

$name = Input::get('name');
$age = Input::get('age');
$things = array('name' => $name, 'age' => $age);
return View::make('view2', $things);

So, you can access $name and $age in your view. Also, you may try this:

return View::make('view2')->with('name', $name)->with('age', $age);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.