當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。