如何告诉Laravel要包含哪些脚本文件

How can I tell Laravel-5 which Javascript files I want to include in a template.

For example, I have my Controller with something like this:

return view('butchery', ['locations' => $locations, 'classTypes' => $classTypes]);

I have my butchery.blade.php template with my html:

@extends('app')
@section('content')
<!-- html here -->
@endsection

...and I have my app.blade.php container template with all my javascript files at the bottom. If I didn't want to include one of the javascript files in my view, how would I do that?

app.blade.php:

<!DOCTYPE HTML>
<!--[if IE 8]><html class="ie8"> <![endif]-->
<!--[if gt IE 8]><!--><html><!--<![endif]-->

<head></head>
<body>@yield('content')</body>
<script src="/js/mobile-menu.js"></script>
<!-- apply voucher code --> 
<script src="/js/voucher-apply.js"></script>
</html>

You should create a section in your template where the scripts should be loaded and use this in your pages to include the required scripts.

Like so:

Template:

<html>
    <head>
        <title>My page</title>
    </head>
    <body>
        <div class="container">
            @yield('content')
        </div>
        @yield('scripts')
    </body>
</html>

Page:

@extends("template")

@section('content')
    <h1>Hello world!</h1>
@stop

@section('scripts')
    <script src="/path/to/script.js"></script>
@stop

This way you can include the scripts on the page that are needed. Scripts that are needed through the entire template can be added under or above the @yield('scripts').

You can use roumen/asset package. It is quite easy to use and will cover all your needs. Just set default set of assets somewhere (e.g. AppServiceProvider) and then in your controller add additional js files that you need only for this particular page. This is the easies way to manage your stack of assets.

Of course you can do that manually. But hen you have to make your view composer that will share array of js files and compile them in your view. Then again make somewhere array of default js/css files and in controller methods extend them.