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'; }
/** * 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()); }
/** * * 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'); }
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'); }
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(); } }
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); }
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'); } }
/** * @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]); }
/** * 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); } }
/** * 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); } }
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']); }
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; }
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!"; } }
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(); }
public function index() { //$book = new \App\Book(); //$books = $book->all(); $books = \App\Book::all(); return view('books', ['books' => $books]); }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('books')->delete(); Book::create(['title' => 'Eugenii Onegin', 'isbn' => '09374726342', 'price' => '10.40', 'cover' => 'onegin.jpg', 'author_id' => '1']); Book::create(['title' => 'Stihi', 'isbn' => '5555555555', 'price' => '8.25', 'cover' => 'esenin_stihi.jpg', 'author_id' => '2']); Book::create(['title' => 'Angels and demons', 'isbn' => '1111111111', 'price' => '15.99', 'cover' => 'brown_angels.jpg', 'author_id' => '3']); }
public function index() { $books = Book::with('Author')->where(function ($query) { $min_price = \Request::has('min_price') ? \Request::get('min_price') : null; $max_price = \Request::has('max_price') ? \Request::get('max_price') : null; $authors = \Request::has('authors') ? \Request::get('authors') : []; if (isset($min_price)) { $query->where('price', '>=', $min_price); } if (isset($max_price)) { $query->where('price', '<=', $max_price); } if (isset($authors)) { $query->where(function ($q) { $input_authors = \Request::has('authors') ? \Request::get('authors') : []; // $books_all = \App\Book::with('Author')->get(); //перебираем все чекнутые боксы foreach ($input_authors as $input_author) { // автор == выборка из авторов где Ид = чекнутому боксу. Первый $author = \App\Author::with('books')->where('id', '=', $input_author)->first(); // выборка внутри выбранного автора по книгам foreach ($author->books as $author_book) { //запрос Айди книги == айди книг у этого автора $q->orWhere('id', '=', $author_book->id); } } }); } })->paginate(2); $authors_list = \App\Author::all(); return view('books.list', compact('books', 'authors_list')); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { $bookUpdate = Request::all(); $book = Book::find($id); $book->update($bookUpdate); return redirect('books'); }
/** * Store a newly created resource in storage. * * @param CreateCartRequest|Request $request * @return Response */ public function store(CreateCartRequest $request) { $book = Book::find($request->bookId); $Quantity = $request->Quantity; Cart::add(['id' => $book->id, 'name' => $book->book_title, 'qty' => $Quantity, 'price' => $book->price, 'options' => array('size' => 'large')]); $cart = $this->getCartsContent(); return view('cart.index', compact('cart')); }
public function updateBook(Request $request, $id) { $Book = Book::find($id); $Book->title = $request->input('title'); $Book->author = $request->input('author'); $Book->save(); return response()->json($Book); }
/** * @Given 書籍 :bookName 已被 :username 借出 */ public function bookCheckedOutByUser($bookName, $username) { $book = Book::where('name', $bookName)->first(); $user = User::where('username', $username)->first(); $book->available = false; $book->save(); factory(CheckoutHistory::class)->create(['book_id' => $book->id, 'user_id' => $user->id]); }
function getExample7() { $book = \App\Book::where('author', 'LIKE', '%Scott%')->first(); if ($book) { return $book->title; } else { return 'Book not found.'; } }
public function store(Requests\User $request) { $all = $request->all(); \App\Book::create($all); echo '<pre>'; print_r($all); die; return redirect('books'); }
/** * Execute the console command. * * @return mixed */ public function handle() { $books = Book::whereRaw('taken < curdate() - interval 30 day')->get(); foreach ($books as $book) { $url = route('books'); $user = User::find($book->user_id); $this->dispatch(new MailSender($user, $book, 'Did you forget to return a book to library?', 'emails.reminder', $url)); } }
/** * @return Redirect */ public function returnBook() { $bookId = Input::get('book_id'); $book = Book::find($bookId); $book->user_id = null; $book->taken = null; $book->save(); return redirect('books'); }
public function show($categoryName) { $books = Book::whereHas('category', function ($q) use($categoryName) { $q->where('name', 'like', $categoryName); })->orderBy('book_added_at', 'desc')->paginate(config('library.posts_per_page')); $imagePath = \Config::get('library.uploads.webpath'); $imageCoverName = \Config::get('library.uploads.cover_name'); $deffaultImage = \Config::get('library.uploads.deffault_image'); return view('allBook', compact('books', 'imagePath', 'imageCoverName', 'deffaultImage')); }
/** * Treat this method as a controller action. * Return view() or other content to display. */ public function run() { // $listItem = Book::where('cate_id', '=', $this->config['id'])->orderBy(DB::raw('RAND()'))->take($this->config['count'])->get(); // return view("widgets.featured_books", [ // 'config' => $this->config, // 'featuredItem' => $featuredItem // ]); return view("widgets.samecategory_books", compact('listItem')); }
public function update($id) { $book = Book::find(\Request::input('book_id')); $book->stock += 1; $book->save(); $data = BookUsers::find($id); $data->status = \Request::input('status'); $data->save(); return redirect('operator/transactions'); }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('lends')->delete(); DB::table('users')->delete(); User::create(['id' => '1', 'name' => '郑文凯', 'email' => '*****@*****.**', 'password' => Hash::make('123'), 'is_admin' => 1, 'reserve_num' => 1]); User::create(['id' => '2', 'name' => '陈翔宇', 'email' => '*****@*****.**', 'password' => Hash::make('1'), 'is_admin' => 0, 'reserve_num' => 10]); DB::table('books')->delete(); Book::create(['id' => '1', 'book_name' => '书名', 'author' => '作者', 'ISBN' => '123456', 'press_name' => '出版社', 'press_date' => '123456', 'url' => '链接', 'in_use' => '0']); Lend::create(['user_id' => '2', 'book_id' => '1', 'lend_date' => '1234', 'due_date' => '2345', 'return_date' => '3456', 'continued' => '1', 'is_returned' => '0']); }
/** * Run the database seeds. * * @return void */ public function run() { $books = ['screen cast' => ['php', 'html', 'css', 'mysql'], 'pdf cast' => ['php', 'html', 'css', 'js'], 'flash cast' => ['forms', 'front-end', 'css', 'js']]; foreach ($books as $title => $tags) { $book = \App\Book::where('title', 'like', $title)->first(); foreach ($tags as $tagName) { $tag = \App\Tag::where('name', 'LIKE', $tagName)->first(); $book->tags()->save($tag); } } }