Laravel: Pass the table of routes to the views without the mapper on some keys?

advertisements

Is it possible? I can do:

Route::get('passit',
    function()
    {
        $data['arr'] = array(1,2,3);
        return View::make('aview', $data);
    });

in the view I do:

foreach ($arr as $a){
    echo $a;
}

The array is mapped with the 'arr'.

What I want instead is just to :

 Route::get('passit',
        function()
        {
            $data = array(1,2,3);
            return View::make('aview', $data);
        });

But this doesn't work because $data in :

foreach ($data as $a){
        echo $a;
    }

Is undefined. I also tried :

Route::get('passit',
            function()
            {
                $data = array(1,2,3);
                return View::make('aview')->with($data);
            });

No luck.

PHP 5.6, Laravel 5.1

Note : By the way, I don't bother, not at all just curious if any.


In your route define the variable as.

return View::make('aview', compact($data));