我有以下博客控制
public function show($slug)
{
$post = Blog::where('slugs', '=', $slug)->first();
$vars['pageTitle'] = Config::get('site.pageTitle') . $post['title'];
// The breadcrumbs... needs to be repopulated every page
$vars['breadCrumbs'] = [[
'url' => action('SimpleController@index'),
'title' => 'CovertDEV'
],[
'url' => action('BlogController@index'),
'title' => 'Blog'
],[
'url' => route('blog_post', ['slug' => $slug]),
'title' => $post['title']
]];
$vars['blog'] = $post;
$vars['comments'] = $post->Blog_comments->groupBy('comment_id');
return view('blog', $vars);
}
以下评论的可怕观点
@php
function display_comments($main, $depth = "\t")
{
foreach($main[0] as $mcomment)
{
@endphp
<div class="media">
<img class="m-3 avatar-sm rounded-1 border border-thick-1 shadow" src="../public/css/images/avatar-placeholder.png" alt="<?=$mcomment->firstname;?> <?=$mcomment->lastname;?>'s Avatar">
<div class="media-body">
<h6 class="mt-0 p-1 lead m-0 border-bottom"><?=$mcomment->firstname;?> <?=$mcomment->lastname;?></h6>
<div class="p-2">
<p><?=$mcomment->comment;?></p>
</div>
@php
if(isset($main[$mcomment->id]))
{
display_child($main, $main[$mcomment->id], $depth);
}
@endphp
</div>
</div>
@php
}
}
function display_child($main, $comment, $depth)
{
foreach($comment as $ccomment)
{
@endphp
<div class="media">
<img class="m-3 avatar-sm rounded-1 border border-thick-1 shadow" src="../public/css/images/avatar-placeholder.png" alt="<?=$ccomment->firstname;?> <?=$ccomment->lastname;?>'s Avatar">
<div class="media-body">
<h6 class="mt-0 p-1 lead m-0 border-bottom"><?=$ccomment->firstname;?> <?=$ccomment->lastname;?></h6>
<div class="p-2">
<p><?=$ccomment->comment;?></p>
</div>
@php
if(isset($main[$ccomment->id]))
{
display_child($main, $main[$ccomment->id], $depth."\t");
}
@endphp
</div>
</div>
@php
}
}
display_comments($comments);
@endphp
这就像它变得丑陋一样。它产生了我想要的东西,但那是丑陋的,非常难看。
This is an image of the created nested comments
在刀片模板中优化工作的最佳方法是什么?我尝试根据docs扩展刀片模板的东西,但这对我来说并不富有成效。我根本无法弄清楚如何去做。
有了这个,我无法调用资产,或类似的东西......那些已经超出范围。