Laravel 5.1 Eager Loading - belongsToMany with parameter
问题 I have this relationship in my Model: public function modulesData($module) { return $this->belongsToMany($module) ->withTimestamps(); } What I want is to eagerload a dynamic relation of my model. But how can I do this? I use this code to eagerload my relation, but how can I add the parameter $module ? $model->with(['modulesData'])->get(); Thanks for reply. 回答1: Consider the following: Define the fallback function to your Model: public function __call($name, $arguments) { if (strpos($name,