假设我有一个包含此内容的视图文件view/admin/users.blade.php
:
@extends('layouts.master')
@section('head')
<link rel="stylesheet" href="/css/style1.css" />
<link rel="stylesheet" href="/css/style2.css" />
@endsection
@section('content')
<div class="row">
<table>
<thead>
<tr>
<th>ID</th>
<th>email</th>
</tr>
</thead>
<tbody>
@foreach($users as $user)
<tr>
<td>{{ $user->id }}</td>
<td>{{ $user->email }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection
@section('scripts')
<script src="/js/script1.js"></script>
<script src="/js/script2.js"></script>
@endsection
是否有任何方法可以将这些部分(每个部分数据)作为数组获取?像这样:
[
'head' => '<link rel="stylesheet" href="/css/style1.css" /><link rel="stylesheet" href="/css/style2.css" />',
'content' => '<div class="row"><table><thead><tr><th>ID</th><th>email</th></tr></thead><tbody>@foreach($users as $user)<tr><td>{{ $user->id }}</td><td>{{ $user->email }}</td></tr>@endforeach</tbody></table></div>',
'scripts' => '<script src="/js/script1.js"></script><script src="/js/script2.js"></script>'
]
答案 0 :(得分:2)
使用renderSections
方法。
$view = view('blade.template')->with(compact('something'));
dd($view->renderSections());
返回由其部分名称键入的assoc数组。