本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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();
}