当前位置: 首页>>代码示例>>PHP>>正文


PHP Photo::with方法代码示例

本文整理汇总了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);
 }
开发者ID:shinichi81,项目名称:laravel4demo,代码行数:8,代码来源:HomeController.php

示例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']);
 }
开发者ID:danielheyman,项目名称:TechDimeProjects,代码行数:32,代码来源:RelationsTest.php

示例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);
 }
开发者ID:jameslcj,项目名称:laraveldemo,代码行数:5,代码来源:photo.php


注:本文中的Photo::with方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。