LoginSignup
1

More than 1 year has passed since last update.

Laravel 特定の子ビューでのみ使用するJSファイルのインポート方法

Last updated at Posted at 2022-03-28

目的

Untitled Diagram.png
共通レイアウト使用時に、子ビューの1つであるfuga.blade.phpのみでfuga.jsを読み込む。

やり方

1.親ビューにスタックを定義する

layout.blade.php
<head>
  @stack('scripts')
<head>

2.子ビューで親ビューのスタックにプッシュする

fuga.blade.php
@push('scripts')
  <script src="{{ mix('js/fuga.js') }}" defer></script>
@endpush

参考

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1