Support the ongoing development of Laravel.io →
Database Eloquent

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} @endforeach

Based 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!

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

elbsurfer elbsurfer Joined 23 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.