Created
August 6, 2015 01:37
-
-
Save vluzrmos/61ce47fa2fb20dae8d73 to your computer and use it in GitHub Desktop.
Example how to remove the eager loading on Eloquent.
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 | |
namespace App; | |
use Illuminate\Database\Eloquent\Model; | |
class Post extends Model | |
{ | |
/** | |
* Array of relationships to load. | |
* @var array | |
*/ | |
protected $with = ['comments']; | |
/** | |
* @return \Illuminate\Database\Eloquent\Relations\HasMany | |
*/ | |
public function comments() | |
{ | |
return $this->hasMany(Comment::class); | |
} | |
/** | |
* @param array $relations | |
* @return static | |
*/ | |
public static function onlyWith($relations = []) | |
{ | |
$instance = new static; | |
$instance->with = $relations; | |
return $instance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment