Hello, i have three database tables: User, Team and Relation. A user can be a member in multiple teams, this is stored in the Relation-table which contains the following attributes:
user_id team_id
Now I have a search field where a user can search for teams - and I want to check if a user has a relation to a certain team within the result. I created the following query:
$teams_obj = Team::where('teamname', 'LIKE', '%'.Input::get('searchterm').'%')->get(); $relation = User::find(Auth::user()->id)->relation;
I return this result to my view as this: return View::make("team.search-content", array('resp' => 'resultlist', 'teams_obj' => $teams_obj, 'relation' => $relation))->with('user', User::find(Auth::user()->id));
Now in my view i created:
@foreach($teams_obj as $team_obj)
<li data-teamid="{{ $team_obj->id }}"> <span>{{ $team_obj->teamname }}</span> {new code to be here} @endforeachBased on the result if a relation between the current user and team result is existing it should be displayed something in {new code to be here} - but how i can check in the view if a relation between the current user and the team result of the respective li element is existing? Any help is much appreciated! Thanks!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community