samedi 17 septembre 2016

Sort in laravel eager loading?

In my laravel project I am loading all the posts, posts author, replies and replies author using eager loading feature.

$pin = Posts::with('author', 'replies', 'replies.author')->find($pin_id);

Here is Replies model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Replies extends Model
{
    public function replyable()
    {
        return $this->morphTo();
    }

    public function author()
    {
        return $this->belongsTo('App\User', 'author_id');
    }

}

Is it possible to sort the replies in descending order by its(replies) id while we fetch all the posts using the eager loading feature.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire