Load all relationships for a model

后端 未结 7 839
名媛妹妹
名媛妹妹 2021-01-01 23:58

Usually to eager load a relationship I would do something like this:

Model::with(\'foo\', \'bar\', \'baz\')...

A solution might be to set

相关标签:
7条回答
  • 2021-01-02 00:40

    You can create method in your Model

    public static function withAllRelations() {
       return static::with('foo', 'bar', 'baz');
    }
    

    And call Model::withAllRelations()

    Or

    $instance->withAllRelations()->first(); // or ->get()

    0 讨论(0)
提交回复
热议问题