本文整理汇总了PHP中Photo::with方法的典型用法代码示例。如果您正苦于以下问题:PHP Photo::with方法的具体用法?PHP Photo::with怎么用?PHP Photo::with使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Photo
的用法示例。
在下文中一共展示了Photo::with方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
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);
}
示例2: testMorph
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']);
}
示例3: action_index
public function action_index()
{
$photos = Photo::with('author')->order_by('created_at', 'desc')->paginate(20);
return View::make('photo.index')->with('photos', $photos);
}