public function index() { $blogs = Blog::with('author')->orderBy('created_at', 'desc')->take(10)->get(); $events = Events::with('author')->orderBy('created_at', 'desc')->take(8)->get(); $groups = Group::with('author')->orderBy('created_at', 'desc')->take(8)->get(); $photos = Photo::with('author')->orderBy('created_at', 'desc')->take(8)->get(); return View::make('home.index')->with('blogs', $blogs)->with('events', $events)->with('groups', $groups)->with('photos', $photos); }
public function testMorph() { $user = User::create(array('name' => 'John Doe')); $client = Client::create(array('name' => 'Jane Doe')); $photo = Photo::create(array('url' => 'http://graph.facebook.com/john.doe/picture')); $photo = $user->photos()->save($photo); $this->assertEquals(1, $user->photos->count()); $this->assertEquals($photo->id, $user->photos->first()->id); $user = User::find($user->_id); $this->assertEquals(1, $user->photos->count()); $this->assertEquals($photo->id, $user->photos->first()->id); $photo = Photo::create(array('url' => 'http://graph.facebook.com/jane.doe/picture')); $client->photo()->save($photo); $this->assertNotNull($client->photo); $this->assertEquals($photo->id, $client->photo->id); $client = Client::find($client->_id); $this->assertNotNull($client->photo); $this->assertEquals($photo->id, $client->photo->id); $photo = Photo::first(); $this->assertEquals($photo->imageable->name, $user->name); $user = User::with('photos')->find($user->_id); $relations = $user->getRelations(); $this->assertTrue(array_key_exists('photos', $relations)); $this->assertEquals(1, $relations['photos']->count()); $photos = Photo::with('imageable')->get(); $relations = $photos[0]->getRelations(); $this->assertTrue(array_key_exists('imageable', $relations)); $this->assertInstanceOf('User', $relations['imageable']); $relations = $photos[1]->getRelations(); $this->assertTrue(array_key_exists('imageable', $relations)); $this->assertInstanceOf('Client', $relations['imageable']); }
public function action_index() { $photos = Photo::with('author')->order_by('created_at', 'desc')->paginate(20); return View::make('photo.index')->with('photos', $photos); }