我想cknow/laravel-money在我的应用程序的几乎每个页面中都使用这个包。我认为一个整洁的方法是在父刀片中导入类。但是,子模板似乎无权访问导入的类。
我试过使用标准<?php ?>标签和@php @endphp指令。
应用程序.blade.php
@php
use Cknow\Money\Money;
@endphp
Run Code Online (Sandbox Code Playgroud)
<title>{{ config('app.name') }}</title>
</head>
<body>
@include('inc.navbar')
@include('inc.flashmessages')
<div class="container">
@yield('content')
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
show.blade.php
<title>{{ config('app.name') }}</title>
</head>
<body>
@include('inc.navbar')
@include('inc.flashmessages')
<div class="container">
@yield('content')
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这抛出。
“找不到‘钱’类。”
而在子类中包含相同的 use 语句按预期工作。