Thursday, March 16, 2017

Collection object with a foreach

i try to run a query who display the licences from the structures who are in relation with the Auth::user()->structure

but i get only the licences from the last "structure" in the collection , i would like all the licences from the $structures collection ..

someone have an idea ? maybe i'm wrong with the query ..

here my controller : 

    public function licenceToValid(){

            // here i grab the collection of the clubs who are in relation with my "comite " **(Comite have many clubs)** 
            $structures = Structure::where(['structure_pere_id' => Auth::user()->structure->id])->get();


            foreach ($structures as $structure) {

                //here the query to display the licences from the structures 
                $licences = Licencies::where('structure_id' , $structure->id)->get();

            }

            return view('licencie/valider' , compact('licencies'));


        }



via Mathieu Mourareau

Advertisement