本文整理汇总了PHP中app\Book类的典型用法代码示例。如果您正苦于以下问题:PHP Book类的具体用法?PHP Book怎么用?PHP Book使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Book类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: foreach
function getExample7()
{
/*$book = new Book();
$results = $book->where('published', '>', 1950)->get();
foreach($results as $result)
{
echo $result->title.'<br/>';
}
echo 'Number found is '.count($results).'<br/>';
return 'example7';*/
$author = new \App\Author();
$author->first_name = 'J.K';
$author->last_name = 'Rowling';
$author->bio_url = 'https://en.wikipedia.org/wiki/J._K._Rowling';
$author->birth_year = '1965';
$author->save();
dump($author->toArray());
$book = new \App\Book();
$book->title = "Harry Potter and the Philosopher's Stone";
$book->published = 1997;
$book->cover = 'http://prodimage.images-bn.com/pimages/9781582348254_p0_v1_s118x184.jpg';
$book->purchase_link = 'http://www.barnesandnoble.com/w/harrius-potter-et-philosophi-lapis-j-k-rowling/1102662272?ean=9781582348254';
$book->author()->associate($author);
# <--- Associate the author with this book
$book->save();
dump($book->toArray());
return 'Example 7';
}
示例2: includeComments
/**
* Include comments.
*
* @param \App\Book $book
* @param \League\Fractal\ParamBag|null $params
* @return \League\Fractal\Resource\Collection
* @throws \Exception
*/
public function includeComments(Book $book, $params)
{
if ($params) {
$this->validateParams($params);
}
list($limit, $offset) = $params->get('limit') ?: config('api.include.limit');
list($orderCol, $orderBy) = $params->get('order') ?: config('api.include.order');
$comments = $book->comments()->limit($limit)->offset($offset)->orderBy($orderCol, $orderBy)->get();
return $this->collection($comments, new \App\Transformers\CommentTransformer());
}
示例3: testProcessBookShow
/**
*
* Tests the module showing details of a single book is working by first adding a new book
* and matching the data inserted vs data seen.
*
*/
public function testProcessBookShow()
{
//create a book
$book = new Book();
$book->title = 'The Hobbit';
$book->author = 'Tolkien';
$book->save();
//see if the created book shows the same details used earlier
$bookShowURL = '/books/' . $book->id;
$this->visit($bookShowURL)->see('Tolkien')->see('The Hobbit');
}
示例4: store
public function store(Request $request)
{
$this->validate($request, ['bk_isbn' => 'required|max:225', 'bk_title' => 'required|max:225', 'bk_author' => 'required|max:225', 'bk_publisher' => 'required|max:225', 'bk_count' => 'required|integer']);
$books = new Book();
$books->bk_isbn = $request->bk_isbn;
$books->bk_title = $request->bk_title;
$books->bk_author = $request->bk_author;
$books->bk_publisher = $request->bk_publisher;
$books->bk_count = $request->bk_count;
$books->bk_desc = $request->bk_desc;
$books->save();
return redirect('books');
}
示例5: run
public function run()
{
DB::table('books')->truncate();
for ($i = 0; $i < 10; $i++) {
$book = new Book();
$book->book_name = str_random(10);
$book->book_auther = str_random(10);
$book->book_press = str_random(10);
$book->book_num = 10;
$book->book_res = 10;
$book->save();
}
}
示例6: schoolClicked
public function schoolClicked($id)
{
$schools = School::all();
$programs = Program::where('school_id', '=', $id)->get();
$books = Book::where('school_id', '=', $id)->get();
return view('home')->with('programs', $programs)->with('schools', $schools);
}
示例7: update
public function update($id)
{
$user_id = \Request::input('user_id');
$checkBorrowCount = BookUser::whereUser_idAndStatus($user_id, 'pinjam')->count();
$checkOrderCount = BookUser::whereUser_idAndStatus($user_id, 'pesan')->count();
$checkCount = $checkBorrowCount + $checkOrderCount;
if ($checkCount < 5) {
$check = BookUser::whereUser_idAndBook_idAndStatus($user_id, $id, 'pinjam')->count();
if ($check < 1) {
$book = Book::find($id);
$book->stock -= 1;
$book->save();
$data = new BookUser();
$data->user_id = $user_id;
$data->book_id = $id;
$data->status = 'pinjam';
$data->save();
return redirect('operator/transactions')->with('successMessage', 'Berhasil meminjam buku.');
} else {
return redirect('operator/borrow')->with('errorMessage', 'User hanya bisa meminjam 1 buku dengan judul yang sama.');
}
} else {
return redirect('operator/borrow')->with('errorMessage', 'User Hanya bisa memesan/meminjam 5 buku');
}
}
示例8: getList
/**
* @return \Illuminate\View\View
*/
public function getList()
{
$currentUser = \Auth::user();
$userBooks = $currentUser->books;
$freeBooks = Book::whereNull('user_id')->paginate(10);
return view('books', ['userBooks' => $userBooks, 'freeBooks' => $freeBooks]);
}
示例9: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$books = [['asin' => '4844339451', 'name' => 'Laravel リファレンス[Ver.5.1 LTS 対応] Web職人好みの新世代PHPフレームワーク'], ['asin' => 'B00WHEJDKK', 'name' => 'Laravelエキスパート養成読本 [モダンな開発を実現するPHPフレームワーク!]'], ['asin' => 'B00F418SQ8', 'name' => 'Vagrant入門ガイド']];
foreach ($books as $book) {
Book::updateOrCreate($book);
}
}
示例10: order
/**
* Proses order buku dari member.
*
* @return Response
*/
public function order($id)
{
if (Auth::user()->name) {
$stock = Book::find($id)->stock;
if ($stock > 0) {
$user_id = Auth::user()->id;
$checkBorrowCount = BookUser::whereUser_idAndStatus($user_id, 'pinjam')->count();
$checkOrderCount = BookUser::whereUser_idAndStatus($user_id, 'pesan')->count();
$checkCount = $checkBorrowCount + $checkOrderCount;
if ($checkCount < 5) {
$checkBorrow = BookUser::whereUser_idAndBook_idAndStatus($user_id, $id, 'pinjam')->count();
$checkOrder = BookUser::whereUser_idAndBook_idAndStatus($user_id, $id, 'pesan')->count();
if ($checkBorrow < 1 && $checkOrder < 1) {
$book = Book::find($id);
$book->stock -= 1;
$book->save();
$data = new BookUser();
$data->user_id = $user_id;
$data->book_id = $id;
$data->status = 'pesan';
$data->save();
return redirect('/')->with('message', 'Berhasil memesan buku ' . $book->title);
} else {
return redirect('/')->withErrors('Hanya bisa memesan/meminjam 1 buku dengan judul yang sama.');
}
} else {
return redirect('/')->withErrors('Hanya bisa memesan/meminjam 5 buku');
}
} else {
return redirect('/')->withErrors('Stok buku kosong');
}
} else {
return redirect('/')->with('requiredName', $id);
}
}
示例11: run
public function run()
{
DB::table('books')->delete();
Book::create(['title' => 'A Tale of Two Cities', 'author' => 'Charles Dickens', 'year' => '1859']);
Book::create(['title' => 'The Lord of the Rings', 'author' => 'J. R. R. Tolkien', 'year' => '1954']);
Book::create(['title' => 'And Then There Were None', 'author' => 'Agatha Christie', 'year' => '1939']);
Book::create(['title' => 'The Hobbit', 'author' => 'J. R. R. Tolkien', 'year' => '1937']);
Book::create(['title' => 'She: A History of Adventure', 'author' => 'H. Rider Haggard', 'year' => '1887']);
Book::create(['title' => 'The Lion the Witch and the Wardrobe', 'author' => 'C. S. Lewis', 'year' => '1950']);
Book::create(['title' => 'The Da Vinci Code', 'author' => 'Dan Brown', 'year' => '2003']);
Book::create(['title' => 'The Catcher in the Rye', 'author' => 'J. D. Salinger', 'year' => '1951']);
Book::create(['title' => 'Lolita', 'author' => 'Vladimir Nabokov', 'year' => '1955']);
Book::create(['title' => 'Anne of Green Gables', 'author' => 'Lucy Maud Montgomery', 'year' => '1908']);
Book::create(['title' => 'The Name of the Rose', 'author' => 'Umberto Eco', 'year' => '1980']);
Book::create(['title' => 'The Eagle Has Landed', 'author' => 'Jack Higgins', 'year' => '1975']);
Book::create(['title' => 'Watership Down', 'author' => 'Richard Adams', 'year' => '1972 ']);
Book::create(['title' => 'The Ginger Man', 'author' => 'J. P. Donleavy', 'year' => '1955']);
Book::create(['title' => 'The Bridges of Madison County', 'author' => 'Robert James Waller', 'year' => '1991']);
Book::create(['title' => 'The Tale of Peter Rabbit', 'author' => 'Beatrix Potter', 'year' => '1902']);
Book::create(['title' => 'Harry Potter and the Deathly Hallows', 'author' => 'J. K. Rowling', 'year' => '2007']);
Book::create(['title' => 'Jonathan Livingston Seagull', 'author' => 'Richard Bach', 'year' => '1970']);
Book::create(['title' => 'A Message to Garcia', 'author' => 'Elbert Hubbard', 'year' => '1899']);
Book::create(['title' => 'Flowers in the Attic', 'author' => 'V. C. Andrews', 'year' => '1979']);
Book::create(['title' => 'War and Peace', 'author' => 'Leo Tolstoy', 'year' => '1869']);
Book::create(['title' => 'The Adventures of Pinocchio', 'author' => 'Carlo Collodi', 'year' => '1881']);
Book::create(['title' => 'Kane and Abel', 'author' => 'Jeffrey Archer', 'year' => '1979']);
Book::create(['title' => 'To Kill a Mockingbird', 'author' => 'Harper Lee', 'year' => '1960']);
Book::create(['title' => 'Valley of the Dolls', 'author' => 'Jacqueline Susann', 'year' => '1966']);
Book::create(['title' => 'Gone with the Wind', 'author' => 'Margaret Mitchell', 'year' => '1936']);
Book::create(['title' => 'The Diary of a Young Girl', 'author' => 'Anne Frank', 'year' => '1947']);
Book::create(['title' => 'One Hundred Years of Solitude', 'author' => 'Gabriel Garcia Marquez', 'year' => '1967']);
Book::create(['title' => 'The Thorn Birds', 'author' => 'Colleen McCullough', 'year' => '1977']);
Book::create(['title' => 'The Revolt of Mamie Stover', 'author' => 'William Bradford Huie', 'year' => '1951']);
Book::create(['title' => 'The Girl with the Dragon Tattoo', 'author' => 'Stieg Larsson', 'year' => '2005']);
}
示例12: borrow2
public function borrow2()
{
//$user = user::where('email', '=', Input::get('bemail'))->firstOrFail();
$returnData = "";
$name = Input::get("name");
$email = Input::get("email");
if (Request::ajax()) {
$userCount = User::where('email', '=', Input::get('email'))->count();
$bookCount = Book::where('barcode', '=', Input::get('barcode'))->count();
if ($userCount == 1) {
$returnData = $returnData . " user existed ";
$user = User::where('email', '=', Input::get('email'))->find(1);
}
if ($userCount == 0) {
$name = Input::get("name");
$email = Input::get("email");
$user = user::create(array('email' => $email, 'name' => $name));
$returnData = $returnData . " user is created ";
}
if ($bookCount == 1) {
$returnData = $returnData . " book existed ";
$book = Book::where('barcode', '=', Input::get('barcode'))->find(1);
}
if ($bookCount == 0) {
$title = Input::get('title');
$author = Input::get('author');
$barcode = Input::get('barcode');
$book = book::create(array('title' => $title, 'author' => $author, 'barcode' => $barcode));
$returnData = $returnData . " book is created ";
}
$borrow = Borrow::create(array('user_id' => $user->id, 'book_id' => $book->id));
$returnData = $returnData . " borrowing is successful user id =" . $user->id . " book id =" . $book->id;
}
return $returnData;
}
示例13: addCart
public function addCart(Request $request)
{
$book = Book::find($request->id);
if ($request->quantity <= $book->quantity) {
$cart_old = Cart::where('book_id', '=', $request->id)->where(function ($query) use($request) {
$query->where('user_id', '=', Auth::check() ? Auth::user()->id : 0)->orWhere('remember_token', '=', $request->header('X-CSRF-TOKEN'));
});
if ($cart_old->count() > 0) {
$check = $cart_old->firstOrFail()->update(['quantity' => $cart_old->firstOrFail()->quantity + $request->quantity]);
} else {
$cart = new Cart();
$cart->user_id = Auth::check() ? Auth::user()->id : null;
$cart->book_id = $request->id;
$cart->quantity = $request->quantity;
$cart->remember_token = $request->header('X-CSRF-TOKEN');
$check = $cart->save();
}
if ($check) {
return "true";
} else {
return "Lỗi thêm hàng vào giỏ. Vui lòng thử lại!";
}
} else {
return "Quá số hàng trong kho. Vui lòng thử lại!";
}
}
示例14: editBook
public static function editBook($data, $id)
{
$book = Book::find($id);
if ($data['title'] != '') {
$book->title = $data['title'];
}
if ($data['isbn10'] != '') {
$book->isbn10 = $data['isbn10'];
}
$author = new Author();
$genre = new Genre();
$author->name = $data['author'];
$genre->name = $data['genre'];
$authorToRemove = Author::find($data['authors']);
$genreToRemove = Genre::find($data['genres']);
$exisitngAuthor = Author::find($data['existing-author']);
$exisitngGenre = Genre::find($data['existing-genre']);
$book->authors()->detach($authorToRemove['author_id']);
$book->genres()->detach($genreToRemove['genre_id']);
$book->authors()->attach($exisitngAuthor['author_id']);
$book->genres()->attach($exisitngGenre['genre_id']);
if ($data['author'] != '') {
$book->authors()->save($author);
var_dump($data['author']);
}
if ($data['genre'] != '') {
$book->genres()->save($genre);
}
$book->save();
}
示例15: index
public function index()
{
//$book = new \App\Book();
//$books = $book->all();
$books = \App\Book::all();
return view('books', ['books' => $books]);
}