Exemplo n.º 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(BookRequest $request)
 {
     $titles = $request->input('titles');
     // $bookclubs = $request->get('bookclubs');
     // $bookIds = [];
     $status_id = \App\BookStatus::availableId();
     if (count($titles)) {
         foreach ($titles as $title) {
             $book = \App\Book::firstOrCreate(['title' => ucfirst($title)]);
             auth()->user()->books()->detach($book->id);
             auth()->user()->books()->attach($book->id, ['status_id' => $status_id]);
             //send mail to user for added books and adding details
             //$bookIds[] =  $bookId => ['status_id' => $status_id];
             // foreach ($bookclubs as $bookclub) {
             //   $book->bookclubs()->detach($bookclub);
             //   $book->bookclubs()->attach($bookclub,['owner_id' => auth()->user()->id]);
             // }
         }
     } else {
         flash()->error('Please enter atleast one Book Title');
         return \Redirect::back();
     }
     flash('Book/Books added to your library.');
     return \Redirect::back();
     /***
           // $book = \App\Book::where('title','=',$request->input('title'))->first();
           // if($book)
           // {
           //   flash('This book already exits add it to your library.');
           //   return \Redirect::route('books.show',$book->id);
           // }
           // $request['author_id'] = auth()->user()->id;
     
           // Convert comma separated string into array of author names
           // $authors = explode(',',$request->get('author'));
     
           //going over author names build up array of author ids by getting author ids and creating author if does not exist
           // $authorIds = [];
           // foreach ($authors as $author) {
             // $authorIds[] =  App\Author::firstOrCreate(['name' => ucfirst($author)])->id;
           // }
           // $request['author_id']  = App\Author::firstOrCreate(['name' => ucfirst(\Input::get('author'))])->id;
           // $request['publisher_id'] = App\Publisher::firstOrCreate(['name' => ucfirst(\Input::get('publisher'))])->id;
           // $request['category_id'] = App\Category::firstOrCreate(['name' => ucfirst(\Input::get('category'))])->id;
           // $request['language_id'] = App\Language::firstOrCreate(['name' => ucfirst(\Input::get('language'))])->id;
     
     
           //create book
           // $book = auth()->user()->books()->create($request->all(),['status_id' => $status_id]);
     
           //atached book to authors
           // $book->authors()->attach($authorIds);
     
           //attach book to book clubs
           // $book->bookclubs()->attach($request->input('bookclubs'),['status_id' => $status_id]);
     
           // flash('Book added.');
           // return \Redirect::back();
           ***/
 }
Exemplo n.º 2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int $id
  * @return Response
  */
 public function update(BookRequest $request, $id)
 {
     $bookUpdate = $request->all();
     $book = \App\Book::find($id);
     $book->update($bookUpdate);
     return redirect('books');
 }
Exemplo n.º 3
0
 public function index(BookRequest $request, PricingService $pricingService, DateService $dateService)
 {
     $oriPickupDate = $request->input('pickupDate');
     $oriReturnDate = $request->input('returnDate');
     $pickupDate = $dateService->getCarbonDateFromDateString($request->input('pickupDate'), 'Y-m-d H:i:s');
     $pickupDateString = $pickupDate->format('l, jS \\of F Y h:i A');
     $returnDate = $dateService->getCarbonDateFromDateString($request->input('returnDate'), 'Y-m-d H:i:s');
     $returnDateString = $returnDate->format('l, jS \\of F Y h:i A');
     $diffString = $pricingService->getDateDiffString($pickupDate, $returnDate);
     // Calculate Price
     $price = $pricingService->getPriceCalculation($pickupDate, $returnDate, $request->input('quantity'));
     $quantity = $request->input('quantity');
     $city = $request->input('city');
     $vespa = Vespa::where('status', '0')->get();
     $avesp = 0;
     foreach ($vespa as $vesp) {
         $avesp = $avesp + $vesp->stock;
     }
     //        Mail::send('emails.approval', ['name'=> 'hehe'], function($message) {
     //            $message->sender(env('SENDER_EMAIL'));
     //            $message->to('*****@*****.**');
     //            $message->subject('Hi');
     //        });
     // dd($avesp);
     return view('book.book', compact('pickupDate', 'returnDate', 'oriPickupDate', 'oriReturnDate', 'pickupDateString', 'returnDateString', 'diffString', 'city', 'price', 'quantity', 'vespa', 'avesp'));
     // dd($avesp);
 }
Exemplo n.º 4
0
 public function update(BookRequest $request, $id)
 {
     $books = Books::find($id);
     $image_name = $books->book_cover;
     if ($request->hasFile('book_cover')) {
         $books->book_cover = ClydeUpload::upload($request->file('book_cover'), $request->file('book_cover')->getClientOriginalName());
         ClydeUpload::exists($image_name) == true ? ClydeUpload::delete($image_name) : false;
     }
     $books->title = $request->title;
     $books->author_id = $request->author_id;
     $books->category_id = $request->category_id;
     $books->resume = $request->resume;
     $books->update();
     return redirect()->route('admin.books.index');
 }
Exemplo n.º 5
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(BookRequest $request)
 {
     if (Input::file('cover')->isValid()) {
         $file = Input::file('cover');
         $destinationPath = 'images/cover';
         $fileName = rand(11111, 99999) . '_' . $file->getClientOriginalName();
         Input::file('cover')->move($destinationPath, $fileName);
         $data = new Book();
         $data->fill($request->all());
         $data->cover = $fileName;
         $data->save();
         return Redirect('admin/books')->with('successMessage', 'Berhasil menambah buku.');
     } else {
         return Redirect()->back();
     }
 }
Exemplo n.º 6
0
 public function postRequest(BookRequest $request)
 {
     $bookRequest = new \App\BookRequest();
     $bookRequest->userid = session('user')->userid;
     $bookRequest->bookname = $request->input('bookname');
     $bookRequest->categoryid = $request->input('categoryid');
     $bookRequest->author = $request->input('author');
     $bookRequest->publishedyear = $request->input('publishedyear');
     $bookRequest->publishername = $request->input('publishername');
     $book = \App\Books::where('bookname', $bookRequest->bookname)->where('author', $bookRequest->author)->where('publishedyear', $bookRequest->publishedyear)->first();
     $bookRequest->save();
     \Session::flash('message', 'Your book request has been placed successfully!');
     \Session::flash('type', 'success');
     return redirect('/books/request');
 }
Exemplo n.º 7
0
 /**
  * Update the specified book resource in storage.
  *
  * @param BookRequest $request App\Http\Requests\BookRequest request
  * @param Book $book           App\Book model
  *
  * @return \Illuminate\Http\Response
  */
 public function update(BookRequest $request, Book $book)
 {
     $book->update($request->only(['title', 'description']));
     return redirect()->action('BooksController@index')->withSuccess("Książka \"{$book->title}\" została zaktualizowana");
 }
Exemplo n.º 8
0
 public function update($id, BookRequest $request)
 {
     $book = Book::findOrFail($id);
     $book->update($request->all());
     return redirect('books');
 }