Jelly, 我在看源代码的时候有个疑问,始终搞不懂,我在eloquent\model里面的 with方法可以 dd($relations),但是在 eloquent buider 里面的with方法中 dd($relations) 始终是空数组,这是为什么?
eloquent\model :
/**
* Begin querying a model with eager loading.
*
* @param array|string $relations
* @return \Illuminate\Database\Eloquent\Builder|static
*/
public static function with($relations)
{
if (is_string($relations)) {
$relations = func_get_args();//['post']
}
// dd($relations);
$instance = new static;
// dd($instance->newQuery());
return $instance->newQuery()->with($relations);
}
eloquent\builder:
/**
* Set the relationships that should be eager loaded.
*
* @param mixed $relations
* @return $this
*/
public function with($relations)
{
dd($relations);
if (is_string($relations)) {
$relations = func_get_args();
}
$eagers = $this->parseWithRelations($relations);
$this->eagerLoad = array_merge($this->eagerLoad, $eagers);
return $this;
}