Passing array from view(Blade) to another view(Blade) in laravel

Solution:

You can just add a yield in your main.blade.php, like this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>@yield('title','My Site')</title>
</head>
<body>
    @yield('container','Content area')

    {{ HTML::script('assets/js/jquery-1.9.0.js') }}

    @yield('javascripts')
</body>
</html>

Then, in your child layout, you add a section for it, like you did. For example:

@section('javascripts')
    @foreach($scripts as $script)
        {{ HTML::script('ets/js/' . $script) }}
    @endforeach
@stop

If you add another child view which doesn’t need to use extra javascripts, Laravel won’t complain because the section is optional.