本文整理汇总了PHP中Book::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::find方法的具体用法?PHP Book::find怎么用?PHP Book::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Book
的用法示例。
在下文中一共展示了Book::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Update a book
*
* @param $book_id
* @return Response
*/
public function update($book_id)
{
$input = Input::only('isbn13', 'title', 'author', 'price');
$book = Book::find($book_id);
$book->update($input);
return Response::json(['data' => $book]);
}
示例2: queryWithoutConstraints
public function queryWithoutConstraints()
{
$books = Book::find(1);
//$books = Book::first();
//$books = Book::all();
Book::pretty_debug($books);
}
示例3: testCanGetResultsAsArrayOfModels
public function testCanGetResultsAsArrayOfModels()
{
self::insertFixture();
$books = Book::find()->all();
$this->assertEquals("My life", $books[0]->title);
$this->assertEquals("My life, II", $books[1]->title);
}
示例4: sandbox
public static function sandbox()
{
// Testaa koodiasi täällä
//View::make('helloworld.html');
$torakat = Book::find(1);
$books = Book::all();
Kint::dump($books);
Kint::dump($torakat);
}
示例5: edit
public function edit($bid)
{
$_action = 'edit';
$_viewtype = 'book/manage';
$_viewdata = array('env' => $this->_env, 'action' => $_action, 'book_id' => $bid);
$book = Book::find($bid);
$_viewdata['book'] = $book;
return View::make($_viewtype, $_viewdata);
}
示例6: testFind
function testFind()
{
$title = "Anathem";
$test_book = new Book($title);
$test_book->save();
$title2 = "Snow Crash";
$test_book2 = new Book($title2);
$test_book2->save();
$result = Book::find($test_book->getId());
$this->assertEquals($result, $test_book);
}
示例7: test_find
function test_find()
{
$title = "Three Blind Mice";
$test_book = new Book($title);
$test_book->save();
$title2 = "Chicken Dog";
$test_book2 = new Book($title2);
$test_book2->save();
$result = Book::find($test_book->getId());
$this->assertEquals($test_book, $result);
}
示例8: testHasOne
/** */
public function testHasOne()
{
$books = Book::find();
foreach ($books as $book) {
$this->assertIsA($book->author, 'Author');
$this->assertIsA($book, 'Book');
}
$this->assertEqual($book->author->name, 'Andrei Cristescu');
// TBD. This is not supported right now!
// $book->author->delete();
// $this->assertEqual(sizeof(Book::find()), 0);
}
示例9: delete
public function delete($id)
{
$exist = Book::where('id', $id)->count();
if ($exist == 0) {
Session::put('msgfail', 'Failed to delete book.');
return Redirect::back()->withInput();
}
$book = Book::find($id);
unlink(public_path() . "/uploads/book/" . $book->file);
Book::where('id', $id)->delete();
Session::put('msgsuccess', 'Successfully deleted book.');
return Redirect::back();
}
示例10: saveBook
public function saveBook()
{
$book = Input::get('book');
$chapters = Input::get('chapters');
$bookMdl = Book::find($book['id']);
$bookMdl->name = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $book['name']);
$bookMdl->urlname = str_replace(' ', '-', iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $book['name']));
$bookMdl->save();
foreach ($chapters as $key => $chapter) {
if ($chapter['id']) {
$chapMdl = Chapter::find($chapter['id']);
} else {
$chapMdl = new Chapter();
}
if ($chapter['id'] && $chapter['isDeleted']) {
$chapMdl->delete();
} else {
$chapMdl->book_id = $chapter['book_id'];
$chapMdl->title = $chapter['title'];
$chapMdl->markerdata = count($chapter['markerdata']) ? json_encode($chapter['markerdata']) : null;
$chapMdl->order = $chapter['order'];
$chapMdl->save();
if (count($chapter['elements'])) {
foreach ($chapter['elements'] as $key => $element) {
if ($element['id']) {
$elementMdl = Element::find($element['id']);
} else {
$elementMdl = new Element();
}
if ($element['id'] && $element['isDeleted']) {
$elementMdl->delete();
} else {
$elementMdl->chapter_id = $chapMdl->id ?: $element['chapter_id'];
$elementMdl->order = $element['order'];
$elementMdl->type = $element['type'];
if ($element['type'] == 4 || $element['type'] == 5) {
$elementMdl->content = json_encode($element['content']);
} else {
$elementMdl->content = $element['content'];
}
$elementMdl->note = $element['note'];
$elementMdl->save();
}
}
}
}
}
echo json_encode(['ok']);
}
示例11: test_find
function test_find()
{
//Arrange
$title = "The Cat in the Hat";
$test_book = new Book($title);
$test_book->save();
$title2 = "Misery";
$test_book2 = new Book($title2);
$test_book2->save();
//Act
$id = $test_book->getId();
$result = Book::find($id);
//Assert
$this->assertEquals($test_book, $result);
}
示例12: testFind
function testFind()
{
//Arrange
$id = null;
$name = "A Series of Unfortunate Events";
$test_book = new Book($id, $name);
$test_book->save();
$name2 = "Fresh Off the Boat";
$test_book2 = new Book($id, $name2);
$test_book2->save();
//Act
$result = Book::find($test_book->getId());
//Assert
$this->assertEquals($test_book, $result);
}
示例13: getPrev
public function getPrev($chid)
{
$_action = 'show';
$chapter = Chapter::find($chid);
$book = Book::find($chapter->book_id);
$firstTextElement = Element::where('chapter_id', '=', $chid)->where('type', '!=', '2')->first();
$firstImage = Element::where('chapter_id', '=', $chid)->where('type', '=', '2')->first();
$tmpELement = ['id' => $firstTextElement['id'], 'chapter_id' => $firstTextElement['chapter_id'], 'order' => $firstTextElement['order'], 'type' => $firstTextElement['type'], 'content' => $firstTextElement['content'], 'note' => $firstTextElement['note']];
if ($firstTextElement['type'] == 4 || $firstTextElement['type'] == 5) {
$tmpELement['content'] = json_decode($firstTextElement['content'], true);
//dd($element['content']);
}
$prevInfo = ['chapter' => $chapter, 'book' => $book, 'info' => $tmpELement ?: null, 'img' => $firstImage ?: null];
echo json_encode($prevInfo, JSON_NUMERIC_CHECK);
}
示例14: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
$data = Request::all();
$rules = ['isbn1' => 'required|numeric', 'isbn2' => 'numeric', 'title' => 'required|alpha', 'publication' => 'required|alpha', 'author' => 'required|numeric', 'subject' => 'required|numeric', 'onstock' => 'required|numeric', 'orderquantity' => 'required|numeric', 'orderlevel' => 'required|numeric', 'price' => 'required|numeric', 'year' => 'required|numeric'];
$message = ['isbn1' => 'ISBN 1 should not be empty.', 'isbn1' => 'ISBN 1 may contain numbers only.', 'isbn2' => 'ISBN 2 may contain numbers only.', 'title' => 'Title should not be empty.', 'title' => 'Title may contain letters only.', 'publicaiton' => 'Publication should not be empty.', 'publicaiton' => 'Publication may contain letters only.', 'author' => 'Author should not be empty.', 'author' => 'Author may contain numbers only.', 'subject' => 'Subject should not be empty.', 'subject' => 'Subect may contain numbers only.', 'onstock' => 'On Stock should not be empty.', 'onstock' => 'On Stock may contain numbers only.', 'orderquantity' => 'Order Quantity should not be empty.', 'orderquantity' => 'Order Quantity may contain numbers only.', 'orderlevel' => 'Order Level should not be empty.', 'orderlevel' => 'Order Level may contain numbers only.', 'price' => 'Price should not be empty.', 'price' => 'Price may contain numbers only.', 'year' => 'Year should not be empty.', 'year' => 'Year may not contain numbers only.'];
$validation = Validator::make($data, $rules, $message);
if ($validation->passes()) {
if (Book::find($data['authorcode'])) {
return back()->withInput();
} else {
}
} else {
return Redirect::back()->withInput()->withErrors($validation);
}
}
示例15: testFind
function testFind()
{
//Arrange
$book_name = "Intro to Art";
$test_book = new Book($book_name);
$test_book->save();
$book_name2 = "Intro to Spanish";
$test_book2 = new Book($book_name2);
$test_book2->save();
//Act
$search_id = $test_book->getId();
$result = Book::find($search_id);
//Assert
$this->assertEquals($test_book, $result);
}