Not sure why Laravel is doing a loop until it's out of memory here. I'm trying to create a has many through relationship with my models, but it's just giving me a white screen. Here are my three models
Contractor.php
class Contractor extends Eloquent {
protected $table = 'contractors';
public function contractorTrades() {
return $this->hasMany('ContractorTrade', 'contractor_id', 'id');
}
}
ContractorTrade.php
class ContractorTrade extends Eloquent {
protected $table = 'contractor_trades';
public function contractor() {
return $this->belongsTo('Contractor');
}
}
Trade.php
class Trade extends Eloquent {
protected $table = 'trades';
}
If I call
Contractor::first()->contractorTrades();
My app runs out of memory and crashes on a white screen with no errors. During my debugging I made it so I was only testing the hasMany before even trying the hasManyThrough and I still cant get it to work. When I run it through Artisan, it looks like it's just looping over and over.
Problem resolved. This might be useful for someone who comes from a Rails background like I do. The perspective of how I was looking at was wrong.
I restructured how my databases was supposed to look like and followed the instructions on the laravel website for the belongsToMany function. I have it working correctly now and it is performing the correct inner join statement.