나는 꽤 오랫동안 작업하고있는 문제가 있습니다.사용자 관련 함수 가져 오기 위치
나는 Laravel 5.0을 사용하고 관계 설정 한 :
- 사용자가 많은 일정
- 을 가질 수있는 여행 일정이 많은 대상
- 사용자는 일정을 통해 많은 목적지를 가지고있을 수 있습니다
이제 많은 컨트롤러에서 필요한 기능을 설정하려고합니다.
public function last_destination() {
return $last_destination =
\App\Destination::where('itinerary_id', auth()->user()->active_itinerary_id)
->orderBy('order_index', 'DESC')
->first();
}
내가 마지막으로 목적지를 검색하려고, 그것은 잘 작동하지만 내가보기에 변수로 최종 목적지를 통과 할 때, 그것은 나에게 오류를 스루 : 나는 User.php에서이 기능이 Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation
다른 클래스에이 함수를 추가해야합니까? 그렇다면 어디에서 $ user-> last_destination()으로 호출 할 수 있습니까?
감사합니다.
고맙습니다. Sebastian
보기에 'last_destination'을 표시하는 데 사용한 코드를 표시 할 수 있습니까? – Johnny
내 컨트롤러에 : '$ last_destination = auth() -> user() -> last_destination(); 보기 ('destinanations.create') -> with ('last_destination', $ last_destination ');' 그리고 내 견해로는 전화. {$ {last_destination [ 'city']}} –