Skip to content
Advertisement

Access Team Model from a collection using logged in user_id

Posted the below not long ago and received some really good answers however whilst developing, my requirements became clearer. Instead of continually editing my previous post, thought I’d make a new one.

How do I return a single Model when working with nested relationships?

Assuming you’ve read my post above, I need to access the Team Model (not collection) for that particular Match for the logged in user. FYI, I’ve named the Model “Team” and then referenced the hasMany function as “players” to the Match Model.

The Team model contains a few columns such as ‘match_id’, ‘user_id’, ‘team’, ‘team_alias’, ‘goals’, ‘assists’, ‘paid’. I need to be able to access these.

Something like this in mind (I want to use this in my blade):

JavaScript

Any ideas on how I can achieve this?

Edit: Adding more details for clarity

My Match Model looks like this:

JavaScript

I use the venue_name, venue_address and match_date_time to display a table of all matches available for a user. A few more options I need to display on this table are whether a person has paid or not. This information is stored in the Team table (once a person submits their availability).

The Team model looks like this:

JavaScript

The Match Model is linked via id to the Team model which contains match_id.

How can I easily access the Team Model for the logged in user from this particular Match model?

Advertisement

Answer

For what i’ve understand, you already have a Match, and a logged user, and you want to find the Team where the logged user play and the Match given right?

JavaScript

or, if you have already implement the realtionship from Match and Team inside the Model, you can do something like

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement