title: laravel How to manage view specific javascript code
body: <p>Hi guys this is my first question. 
  I'm having trouble on how to organize my javascript with laravel. 
  I Have some public java-script which should be included in every page, and some page or view specific scripts. 
  my approach now is a separate include file filled with {if} statements wrapping the view specific scripts and I pass the page name to the view to load the appropriate scripts and it look like this.</p>
  
  <p>this is the routing code to get the page name from the url:</p>
  
  <pre><code>Route::get('project/{section?}', 'ProjectController@index');
  </code></pre>
  
  <p>this is the controller </p>
  
  <pre><code>class ProjectController extends Controller
      {
          //
          public function index($section = 'pitch')
          {
              $page = 'project';
              if ($section == 'pitch') {
                  return view('pages.project.pitch', compact('page', 'section'));
              } elseif ($section == 'business_details') {
                  return view('pages.project.businessDetails', compact('page', 'section'));
              } elseif ($section == 'marketing_sales') {
                  return view('pages.project.marketingSales', compact('page', 'section'));
              } elseif ($section == 'staff') {
                  return view('pages.project.staff', compact('page', 'section'));
              } else {
                  return view('pages.project.pitch', compact('page', 'section'));
              }
          }
      }
  </code></pre>
  
  <p>and this is a sample{{not the full code !}} of my included scripts.blade.php</p>
  
  <pre><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
          integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
          crossorigin="anonymous"&gt;&lt;/script&gt;
  @if(isset($page) &amp;&amp; $page == 'explore')
      &lt;script type="text/javascript"
              src="https://maps.googleapis.com/maps/api/js?key=AIzaSyATVGl-q2F19QoSxS-h1amZLEQ0hzTU3sQ"&gt;&lt;/script&gt;
      &lt;script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"&gt;&lt;/script&gt;
  @elseif(isset($page) &amp;&amp; $page == 'home')
  @elseif(isset($page) &amp;&amp; $page == 'project' &amp;&amp; $section == 'pitch')
      &lt;script src="/js/pie-chart.js"&gt;&lt;/script&gt;
  @elseif(isset($page) &amp;&amp; $page == 'project' &amp;&amp; $section == 'business_details')
      &lt;script type="text/javascript"
              src="https://maps.googleapis.com/maps/api/js?key=AIzaSyATVGl-q2F19QoSxS-h1amZLEQ0hzTU3sQ"&gt;&lt;/script&gt;
  @elseif(isset($page) &amp;&amp; $page == 'project' &amp;&amp; $section == 'marketing_sales')
      &lt;script src="/js/pie-chart.js"&gt;&lt;/script&gt;
  
  @elseif(isset($page) &amp;&amp; $page == 'project' &amp;&amp; $section == 'staff')
      &lt;script src="https://cdn.rawgit.com/nnattawat/flip/master/dist/jquery.flip.min.js"&gt;&lt;/script&gt;
  @endif
  </code></pre>
  
  <p>this approach is exhausting and it feels like there is a better so is there ?
  thanx for ur help in advance</p>