Support the ongoing development of Laravel.io →
Database Eloquent Views
Last updated 2 years ago.
0

Where is your matchs table/model ?

Last updated 2 years ago.
0
Table: event_matches

id    eventID    matchNumber    matchTypeID 
1        1                    1                      1
<?php

class Match extends \Eloquent {
	
	// LINK THIS MODEL TO OUR DATABASE TABLE ---------------------------------
	protected $table = 'events_matches';
	
	// DEFINE RELATIONSHIPS --------------------------------------------------
	public function event()
    {
        return $this->belongsTo('Events');
    }
    
    public function type()
    {
	    return $this->belongsTo('MatchType', 'match_type_id');
    }
    
    public function stipulation()
    {
        return $this->belongsTo('MatchStipulation', 'match_stipulation_id');
    }
    
    public function title()
    {
        return $this->belongsTo('Title');
    }
    
    public function competitors()
    {
        return $this->hasMany('EventMatchesAppearances');
    }
    
}
Last updated 2 years ago.
0

I don't understand the problem. You want to get the roster name of the competitor ? Isn't it just a relationship between roster and competitor ?

Last updated 2 years ago.
0

Yes however I'm trying to figure out how to get that relationship to show up when I need to echo the roster name of the competitor.

How should I be getting the roster name?

Last updated 2 years ago.
0
foreach($match->competitors as $competitor){

  echo $competitor->roster->roster_name;

}

Assuming that

class Competitor extends Eloquent{

  public function roster(){

    return $this->belongsTo('Roster');

  }

}
Last updated 2 years ago.
0

I have the following actually and I am getting the following error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'roster.event_matches_appearances_id' in 'where clause' (SQL: select * from `roster` where `roster`.`event_matches_appearances_id` = 1)

I'm trying to figure out what I need to do so that it will get the correct roster_name correctly.

<?php

class EventMatchesAppearances extends Eloquent {

	// LINK THIS MODEL TO OUR DATABASE TABLE ---------------------------------
	protected $table = 'event_matches_appearances';
	
	// DEFINE RELATIONSHIPS --------------------------------------------------
	public function roster()
    {
        return $this->hasMany('Roster');
    } 
    
}
Last updated 2 years ago.
0

You can override the default foreign key names when defining the relationship. Check the doc on eloquent relationships.

Last updated 2 years ago.
0

I get the correct query run to get the wrestler however when I try and echo his name it does not work. It errors saying undefined property::$roster_name.

@foreach($match->competitors AS $competitor)
    {{ $competitor->roster->roster_name }}
@endforeach
Last updated 2 years ago.
0

I did some further research and found I have to do an additional foreach statement and loop over it. The solution is as follows.

@foreach ($match->competitors AS $competitor)
    @foreach ($competitor->roster AS $member)
        {{ $member->roster_name }}
    @endforeach
@endforeach
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.

© 2024 Laravel.io - All rights reserved.