获取laravel中的post comment order by

获取laravel中的post comment order by,laravel,Laravel,我想获取在创建时创建的注释顺序,但我如何才能做到这一点? 我照常按命令做了,但没用。 @foreach($post->comnt->take(1)->orderBy('created_at','DESC')作为$comments) @if($post->comnt) @foreach($post->comnt->take(1)as$comments) 用户->图像}“alt=”“> {{$comments->comment} @endforeach @恩迪夫 这是我的海报模型 <?php

我想获取在创建时创建的注释顺序,但我如何才能做到这一点? 我照常按命令做了,但没用。 @foreach($post->comnt->take(1)->orderBy('created_at','DESC')作为$comments)

@if($post->comnt)
@foreach($post->comnt->take(1)as$comments)
用户->图像}“alt=”“>

{{$comments->comment}

@endforeach @恩迪夫
这是我的海报模型

<?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');
}

}
可能吧

public function comnt()
{
    return $this->hasMany('App\comment')->orderBy('created_at','DESC');
}

显示模型代码
public function comnt()
{
    return $this->hasMany('App\comment')->orderBy('created_at','DESC');
}