0

I'm using the group logic to filter the admin section of my website. I have a routing like this:

Route::group(array('before' => 'auth'), function() {

    $datas['user']['email'] = Auth::user()->email;

    Route::get('admin/dashboard', function() {
        return View::make('admin/dashboard')->with(array('datas' => $datas));
    });
    //other routes...
});

How to make $datas available to all routes that are included in my group ?

Patrick L.
  • 526
  • 6
  • 24

2 Answers2

0

You can share variables:

View::share('datas', $datas);
return View::make('admin/dashboard');
Eimantas Gabrielius
  • 1,356
  • 13
  • 15
0

As you stated that you'd like to include $datas in every route, you can make use of the use keyword:

Route::group(array('before' => 'auth'), function()
{
    $datas['user']['email'] = Auth::user()->email;

    Route::get('admin/dashboard', function() use ($datas)
    {
        return View::make('admin/dashboard')->with(array('datas' => $datas));
    });
});

You can learn about the use keyword here.

Community
  • 1
  • 1
Mike Rockétt
  • 8,947
  • 4
  • 45
  • 81