I want to get all the projects through a group. I got that working now, but I can't seem to get the right ID's. I keep getting 1 as the ID for all my posts. Am I doing something wrong?
ProjectController.php
public function index()
{
$projects = \Auth::user()->projects;
dd($projects);
return view('projects.home', compact('projects'));
}
User.php
public function projects()
{
return $this->hasManyThrough(
'App\Project', 'App\Group',
'id', 'group_id', 'group_id'
);
}
Dump (all items have the same attribute > id, all the other attributes are good)
Collection {#224 ▼
#items: array:8 [▼
0 => Project {#225 ▼
#table: "projects"
#connection: null
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:7 [▼
"id" => 1
"name" => "project.com"
"display_name" => "Project 1"
"group_id" => 1
"active" => 0
"created_at" => null
"updated_at" => "2017-03-29 12:21:47"
]
#original: array:7 [▶]
#casts: []
#dates: []
#dateFormat: null
#appends: []
#events: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
#guarded: array:1 [▶]
}
1 => Project {#226 ▶}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire