【发布时间】:2017-03-03 21:07:53
【问题描述】:
我想通过 created at 获取评论顺序,但我该怎么做? 我照常做,但没有用。 @foreach( $post->comnt->take(1)->orderBy('created_at','DESC') as $cmets )
@if($post->comnt)
<div class="comments clearfix">
@foreach( $post->comnt->take(1) as $comments )
<div class="each_coments clearfix">
<p> <span class="comment_profile"><img src="{{ asset('img').'/'.$comments->user->image }}" alt=""></span></p>
<p><a href=" {{ route('postUserinfo', [ 'id' => $post->user_id ]) }} ">{{ $comments->user->username }}</a>{{ $comments->comment }}</p>
</div><?php $last_id = $comments->id ?>
@endforeach
<a data-lastid="@if(!empty($last_id)){{$last_id}}@else{{'0'}}@endif" href="">lode more comments</a>
</div>
<?php unset($last_id); ?>
@endif
这是我的帖子模型
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
protected $table = 'posts';
public function user()
{
return $this->belongsTo('App\User');
}
public function likes()
{
return $this->hasMany('App\like');
}
public function comnt()
{
return $this->hasMany('App\comment');
}
}
【问题讨论】:
-
显示型号代码
标签: laravel