lundi 16 janvier 2017

Laravel belongsTo messes up pagination

A job has multiple tasks and one task belongs to a client.

Model:

   public function client(){
        return $this->belongsTo('\App\Client');
    }

View:

 // these work fine
 // works fine on 1st page, 
                     // Trying to get property of non-object on all other pages.



Controller:

$tasks = $job->tasks()->paginate(5);

I need something like this (I don't know the exact syntax), which adds the client data so that works with the pagination.

$tasks = $job->tasks()->with('client')->paginate(5); // ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire