jeudi 23 février 2017

Laravel: Passing array from routes to views without mapping it to some keys?

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.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2mbkPME
via IFTTT

Aucun commentaire:

Enregistrer un commentaire