The correct limit and take in the Larave with () function

//
class essay extends Model
{
    public function comment()
    {
        return $this->hasMany("App\comment")
    }
}

//
class comment extends Model
{
    public function essay()
    {
        return $this->belongsTo("App\essay")
    }
}

how to get the first 10 comments in each article

// 10
essay::with(["comment" => function($query) {
    $query->take(10)
}])

ask all the bosses to help

Feb.27,2021

with means eager loading. It means to "crave out" the associated information when you need it. So if you want to get the top 10 comments in each article, you have to find all the articles and then load the comments for each article.

essay::get()->comment()->take(10);

from: https://codeshelper.com/a/11. there are two ways to do this. You have tested it yourself, but you should pay attention to the following.

/ / the first method, the third method written by the author.

$sub = Comment::whereIn('post_id',$postIds)->select(DB::raw('*,@post := NULL ,@rank := 0'))->orderBy('id');
Change

to

$sub = Comment::whereIn('post_id',$postIds)->select(DB::raw('*,@post := NULL ,@rank := 0'))->orderBy('post_id');

/ / the second method is the first netizen (Night Shadow) under the URL comment


I am trying to read java and want to fix in String coding values, but the updating Console. Read complete about Buy Essay and String (" Enter a real value of string: ") does not actually work.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b99762-2f178.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b99762-2f178.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?