Laravel 8 给子视图取别名
如果您的 Blade 包含了一个存储于子目录中的视图,您可能希望给它们取一个别名以方便访问。例如,假设存储于 resources/views/includes/input.blade.php 的视图拥有如下内容:
<input type="{{ $type ?? 'text' }}">
您可以使用 include 为 includes.input 取一个名为 input 的别名。通常情况下,这需要在 AppServiceProvider 中的 boot 方法中完成:
use Illuminate\Support\Facades\Blade;
Blade::include('includes.input', 'input');
一旦您为子视图取了别名,您便可在 Blade 指令中使用别名来对其进行渲染:
@input(['type' => 'email'])