Created
April 25, 2015 11:41
-
-
Save Metrakit/ac471806be94ad8343c4 to your computer and use it in GitHub Desktop.
Eager loading de la mort qui tue thanks to Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Master Model (Top.php) | |
class Top extends Eloquent { | |
public function topServer() | |
{ | |
return $this->hasOne('TopServer'); | |
} | |
public function topSite() | |
{ | |
return $this->hasOne('TopSite'); | |
} | |
public function topProduct() | |
{ | |
return $this->hasOne('TopProduct'); | |
} | |
} | |
// Model (TopServer.php) | |
class TopServer extends Eloquent { | |
/** | |
* Jointe sur les serveurs | |
* @return {[type]} [description] | |
*/ | |
public function server() | |
{ | |
return $this->hasMany('Server'); | |
} | |
// Jointures sur les serveurs avec pivot | |
public function gameType() | |
{ | |
return $this->belongsToMany('Gametype'); | |
} | |
} | |
$top = Top::with('topserver', 'topserver.gametype', 'topserver.server')->findOrFail($top_id); | |
var_dump($top) = WTF OBJECT !!!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment