我的控制器:
class Comments extends Controller {
public function GenerateComments($id){
$theme = DB::table('New_Themes')
->where('id', $id)
->get();
$Comments = NewTheme_Comment::where('id_theme', $id)->get();
return view('comments', ['Themes'=>$theme, 'Comments'=>$Comments]);
}
Run Code Online (Sandbox Code Playgroud)
我的表(NewTheme_Comment):
id
parent_id
id_theme
user
text
upVotes
downVotes
Run Code Online (Sandbox Code Playgroud)
我的视图(包含reddit中相同的注释树的递归显示),......(数据)包含引导媒体对象,并且</div>用于向上(视觉上)树的评论应该是:
<?php
tree($Comments, 0, 0);
$var = -1;
function tree($Comments, $parent_id = 0, $level=0, $c=0) {
global $var;
foreach($Comments as $Comment) {
if($Comment['parent_id'] == $parent_id) {
If ($level > $var) $var++; else {
for ($i = $var-$level+1; $i>0; $i--) { if ($c < 0) echo '</div> </div>'; else $c--; };
$var=$level;
};
echo '........(data)';
tree($Comments, $Comment['id'], $level+1,$c);
};
};
};
?>
Run Code Online (Sandbox Code Playgroud)
问题是.........(数据)应该包含这些东西:
<div class="media">
<div class="media-left">
<a href="{{route('vote', ['id' => $Comment->id, 'vote' => 'plus' ])}}"> <img class="media-object" style="height:40px; width:40px;" src="{{ URL::asset("images/upVote.svg") }}" ></a>
<div>{{$Comment->upVotes-$Comment->downVotes}}</div>
<a href="{{route('vote', ['id' => $Comment->id, 'vote' => 'minus' ])}}"><img class="media-object" style="height:40px; width:40px;" src="{{ URL::asset("images/downVote.svg") }}" ></a>
</div>
<div class="media-body">
<p class="media-heading">{{ $Comment->text }}</p>
<p class="media-heading">{{ $Comment->user }} / {{ $Comment->created_at }} </p>
Run Code Online (Sandbox Code Playgroud)
而我正在使用此线以上的刀片 ,我无法将其整合到视图中的回声中,取代..........(数据).我有直觉,我应该集成到控制器中的功能,但我坏了(我花了很多时间在显示注释的递归方法),我不知道如何获取数据并以递归方式打印出整个单元.
任何帮助,不胜感谢找到出路这个烂摊子的,非常感谢你
编辑1:
如果我在........(数据)中填充bootstrap媒体对象,这是一个例子:
<div class="media">
<a class="media-left" href="#">
<img class="media-object" src="..." alt="...">
</a>
<div class="media-body">
<h4 class="media-heading">Media heading</h4>
Without 2 x </div>
Run Code Online (Sandbox Code Playgroud)
Min*_*dir 13
您正在以错误的方式接近视图,因为刀片模板不是要使用功能,最好遵循以下建议.
最好的方法是将功能代码放在刀片文件中,例如recursive.blade.php:
@foreach($comments as $comment)
//place your code here
@endforeach
Run Code Online (Sandbox Code Playgroud)
然后在主刀片中,您可以多次调用它:
<div>
@include('recursive', ['comments' => $comments])
</div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2730 次 |
| 最近记录: |