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


PHP Book::author方法代码示例

本文整理汇总了PHP中Book::author方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::author方法的具体用法?PHP Book::author怎么用?PHP Book::author使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Book的用法示例。


在下文中一共展示了Book::author方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: bookInsertion

 function bookInsertion($title, $ISBN, $author)
 {
     $book = new \Book();
     $book->title = $title;
     $book->isbn = $ISBN;
     $book->author()->associate($author);
     $book->save();
     return $book;
 }
开发者ID:Big-Shark,项目名称:php-orm-benchmark,代码行数:9,代码来源:TestDefault.php

示例2: runBookInsertion

 function runBookInsertion($i)
 {
     $book = new Book();
     $book->title = 'Hello' . $i;
     $book->author()->associate($this->authors[array_rand($this->authors)]);
     $book->isbn = '1234';
     $book->price = $i;
     $book->save();
     $this->books[] = $book;
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:10,代码来源:EloquentTestSuite.php

示例3: testSetOnBelongsToRelationship

 function testSetOnBelongsToRelationship()
 {
     $person = new Person();
     $person->firstName = 'John';
     $person->age = 22;
     $book = new Book();
     $book->title = 'Obama Wins!';
     $book->setAuthor($person);
     $this->assertEquals($book->author()->id, $person->id);
 }
开发者ID:amitshukla30,项目名称:recess,代码行数:10,代码来源:ModelTest.php

示例4: run

 public function run()
 {
     # Clear the tables to a blank slate
     DB::statement('SET FOREIGN_KEY_CHECKS=0');
     # Disable FK constraints so that all rows can be deleted, even if there's an associated FK
     DB::statement('TRUNCATE books');
     DB::statement('TRUNCATE authors');
     DB::statement('TRUNCATE tags');
     DB::statement('TRUNCATE book_tag');
     DB::statement('TRUNCATE users');
     # Authors
     $fitzgerald = new Author();
     $fitzgerald->name = 'F. Scott Fitzgerald';
     $fitzgerald->birth_date = '1896-09-24';
     $fitzgerald->save();
     $plath = new Author();
     $plath->name = 'Sylvia Plath';
     $plath->birth_date = '1932-10-27';
     $plath->save();
     $angelou = new Author();
     $angelou->name = 'Maya Angelou';
     $angelou->birth_date = '1928-04-04';
     $angelou->save();
     # Tags (Created using the Model Create shortcut method)
     # Note: Tags model must have `protected $fillable = array('name');` in order for this to work
     $novel = Tag::create(array('name' => 'novel'));
     $fiction = Tag::create(array('name' => 'fiction'));
     $nonfiction = Tag::create(array('name' => 'nonfiction'));
     $classic = Tag::create(array('name' => 'classic'));
     $wealth = Tag::create(array('name' => 'wealth'));
     $women = Tag::create(array('name' => 'women'));
     $autobiography = Tag::create(array('name' => 'autobiography'));
     # Books
     $gatsby = new Book();
     $gatsby->title = 'The Great Gatsby';
     $gatsby->published = 1925;
     $gatsby->cover = 'http://img2.imagesbn.com/p/9780743273565_p0_v4_s114x166.JPG';
     $gatsby->purchase_link = 'http://www.barnesandnoble.com/w/the-great-gatsby-francis-scott-fitzgerald/1116668135?ean=9780743273565';
     # Associate has to be called *before* the book is created (save())
     $gatsby->author()->associate($fitzgerald);
     # Equivalent of $gatsby->author_id = $fitzgerald->id
     $gatsby->save();
     # Attach has to be called *after* the book is created (save()),
     # since resulting `book_id` is needed in the book_tag pivot table
     $gatsby->tags()->attach($novel);
     $gatsby->tags()->attach($fiction);
     $gatsby->tags()->attach($classic);
     $gatsby->tags()->attach($wealth);
     $belljar = new Book();
     $belljar->title = 'The Bell Jar';
     $belljar->published = 1963;
     $belljar->cover = 'http://img1.imagesbn.com/p/9780061148514_p0_v2_s114x166.JPG';
     $belljar->purchase_link = 'http://www.barnesandnoble.com/w/bell-jar-sylvia-plath/1100550703?ean=9780061148514';
     $belljar->author()->associate($plath);
     $belljar->save();
     $belljar->tags()->attach($novel);
     $belljar->tags()->attach($fiction);
     $belljar->tags()->attach($classic);
     $belljar->tags()->attach($women);
     $cagedbird = new Book();
     $cagedbird->title = 'I Know Why the Caged Bird Sings';
     $cagedbird->published = 1969;
     $cagedbird->cover = 'http://img1.imagesbn.com/p/9780345514400_p0_v1_s114x166.JPG';
     $cagedbird->purchase_link = 'http://www.barnesandnoble.com/w/i-know-why-the-caged-bird-sings-maya-angelou/1100392955?ean=9780345514400';
     $cagedbird->author()->associate($angelou);
     $cagedbird->save();
     $cagedbird->tags()->attach($autobiography);
     $cagedbird->tags()->attach($nonfiction);
     $cagedbird->tags()->attach($classic);
     $cagedbird->tags()->attach($women);
     $user = new User();
     $user->email = 'sam@gmail.com';
     $user->password = Hash::make('sam1234');
     $user->first_name = 'Sam';
     $user->last_name = 'Seaborn';
     $user->save();
 }
开发者ID:rebekahheacock,项目名称:dwa15-archive,代码行数:77,代码来源:FoobooksSeeder.php


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