是否可以更改get
Laravel 中 a 的“基础”?
为了解释我,如果我执行这个:
$books = App\Book::with('author')->get();
dd($books);
我会得到这样的东西:
Illuminate\Database\Eloquent\Collection {#903
all: [
App\Book {#932
id: 1,
name: "book1",
author: Illuminate\Database\Eloquent\Collection {#939
all: [
App\Author{#945
id: 1,
name: "pippo"
},
],
},
},
],
}
所以“基地”是Book
,我想有基地Author
,就像这样:
Illuminate\Database\Eloquent\Collection {#939
all: [
App\Author{#945
id: 1,
name: "pippo"
},
],
},
或这个:
Illuminate\Database\Eloquent\Collection {#939
all: [
App\Author{#945
id: 1,
name: "pippo"
book: Illuminate\Database\Eloquent\Collection {
id: 1,
name: "book1",
},
},
],
},
以某种方式可能吗?
PS:就我而言,我无法更改 get 方法,所以第一部分
$books = App\Book::with('author')
无法改变