So my Client model has a hasMany relationship with the Project model, because every client in the client table is associated with many projects in the projects table.
The method looks like this:
Client.php:
public function projects()
{
return $this->hasMany('App\Projects', 'id', 'project_id');
}
Seems pretty straightforward. But when I try this from a controller:
$projects = Client::find(1)->projects()->get()
I get only a single result, the FIRST result, from the Project model, when there should be about a half dozen. This even happens if I change the integer sent to find().
So Eloquent is returning on the first row of the projects table every time. Why is it doing this and/or how can I get all of the relevant results?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2k7YRFG
via IFTTT
Aucun commentaire:
Enregistrer un commentaire