2014-11-20 2 views
0

내 경로 코드전화 와 웅변 컬렉션 :()

return View::make('test')->with('foo', foo::all()->with('foos', 'bars')); 

는이 예외를 던지는 이유?

+1

클래스 컬렉션 방법 '이없는 with' http://laravel.com/ api/4.2/Illuminate/Database/Eloquent/Collection.html'foo :: all()'은 Query Builder Builder 인스턴스가 아닌 Collection (모든 엔티티, 배열과 같은)을 반환합니다. http://laravel.com/api /4.2/Illuminate/Database/Eloquent/Builder.html – Cheery

+0

http://laravel.com/api/4.2/Illuminate/Database/Eloquent/Builder.html#method_with –

+1

예, 'with' 메소드가 있습니다. Collection 클래스의 메소드가 아니라 Builder 클래스의 메소드. 콜렉션 ('all()'에 의해 얻어 짐)은 실행 된 질의의 결과이며, 그것을 요구해야만하는 질의가 아니라 데이터베이스로부터의 모든 데이터를 포함한다. – Cheery

답변

2

all() 함수는 쿼리를 실행하므로 컬렉션을 얻을 수 있습니다. 쿼리 작성기 인스턴스에 with을 호출해야합니다. 이 작업을 수행해야 의미가 Foo해야한다, 그래서 또한

foo::with('foos', 'bars')->get(); 

을, 클래스가 관례 대문자로 시작)