<?php
class Index{
// item_id / item_type
public function item(){
return $this->morphTo();
}
}
class SampleItem{
public function indexes(){
return $this->morphMany('Index', 'item');
}
public function user(){
return $this->belongsTo('User');
}
}
class User{
//
}
// This nicely eager loads all of the morphed relations
$items = Index::with('item')->get();
// Accessing the "user" property on a item would result in a query every time.
foreach($items as $item){
$test = $item->user;
}