diff --git a/app/Http/Controllers/Crud/BooksAPIController.php b/app/Http/Controllers/Crud/BooksAPIController.php index 08be304..c4f57d3 100644 --- a/app/Http/Controllers/Crud/BooksAPIController.php +++ b/app/Http/Controllers/Crud/BooksAPIController.php @@ -23,7 +23,7 @@ public function getBooks() } catch (\Exception $e) { - return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine()); + log::error($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine()); } diff --git a/app/Http/Controllers/Crud/BooksController.php b/app/Http/Controllers/Crud/BooksController.php index 6c50a4e..771efd7 100644 --- a/app/Http/Controllers/Crud/BooksController.php +++ b/app/Http/Controllers/Crud/BooksController.php @@ -7,7 +7,7 @@ use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Validator; -use Illuminate\Support\Facades\DB; + class BooksController extends Controller { @@ -29,7 +29,7 @@ public function userbooks() return view('user.userbooks', ['showdata' => $Books]); } catch (\Exception $e) { - return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine()); + return redirect('errors')->withErrors( 'OOPS.! Error In Loading... Books.'); } @@ -46,7 +46,7 @@ public function storeNewBook(Request $request) ]); if ($validator->fails()) { - return redirect('errors') + return back() ->withErrors($validator) ->withInput(); } @@ -56,10 +56,10 @@ public function storeNewBook(Request $request) $data = new BookShopLib(); $data->storeNewBook($request); - return redirect('/adminbooks'); + return back(); } catch (\Exception $e) { - return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine()); + return back()->withErrors( 'OOPS.! Error In Creating New Book.'); } @@ -72,10 +72,10 @@ public function bookdelete(Request $request) $delBook = new BookShopLib(); $delBook->bookdelete($request->book_del_id); - return redirect('/adminbooks'); + return back(); } catch (\Exception $e) { - return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine()); + return back()->withErrors( 'OOPS. Error In Book Delete..!'); } } @@ -90,7 +90,7 @@ public function bookUpdate(Request $request) ]); if ($validator->fails()) { - return redirect('errors') + return back() ->withErrors($validator) ->withInput(); } @@ -98,25 +98,22 @@ public function bookUpdate(Request $request) $bookUpdate = new BookShopLib(); $bookUpdate->bookUpdate($request); - return redirect('/adminbooks'); + return back(); } catch (\Exception $e) { - return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine()); + return back()->withErrors( 'OOPS.! Error In Book Update.'); } } + // Method to display error on a page. public function errors() { - try { - return view('post.errors'); + return view('post.errors'); + } - } catch (\Exception $e) { - return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine()); - } - } } diff --git a/app/Http/Controllers/Crud/BuyBooksController.php b/app/Http/Controllers/Crud/BuyBooksController.php index 70d78c5..18b8067 100644 --- a/app/Http/Controllers/Crud/BuyBooksController.php +++ b/app/Http/Controllers/Crud/BuyBooksController.php @@ -16,14 +16,14 @@ public function storeBookAfterBuy(Request $request) { try { $data = new BuyBookShopLib(); - $data->storeBookAfterBuy($request); + return $data->storeBookAfterBuy($request); - return redirect('buydbooks'); +// return redirect('buydbooks')->with('success', ['New Book Successfully Createsdasdasdad.']); } catch (\Exception $e) { - return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine()); + return redirect('userbooks')->withErrors( 'OOPS.! Error In purchesing Book.'); } @@ -34,17 +34,10 @@ public function storeBookAfterBuy(Request $request) public function viewBooksAfterBuy() { - try { - $data = new BuyBookShopLib(); + $data = new BuyBookShopLib(); $data = $data->viewBooksAfterBuy(); - return view('user.Buydbooks', ['buydbooks' => $data]); - - } catch (\Exception $e) { - return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine()); - - - } + return view('user.Buydbooks', ['buydbooks' => $data]); } diff --git a/app/Lib/Crud/BookShopLib.php b/app/Lib/Crud/BookShopLib.php index e581ee8..ec3bf51 100644 --- a/app/Lib/Crud/BookShopLib.php +++ b/app/Lib/Crud/BookShopLib.php @@ -38,12 +38,13 @@ public function storeNewBook($data) $saveBooks->special_price = $data->special_price; $saveBooks->book_created_date = $data->book_created_date; $saveBooks->quantity = $data->quantity; + $saveBooks->save(); - return $saveBooks->save(); + return back()->with('success', ['New Book Successfully Created.']); } catch (\Exception $e) { - return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine()); + return back()->withErrors( 'OOPS.! Error In Creating New Book.'); } @@ -53,12 +54,19 @@ public function storeNewBook($data) public function bookdelete($id) { try { - $delBook = Book::destroy($id); - - return $delBook; + Book::destroy($id); +// if (!empty($bookdel)) +// {- +// return back()->with('success', ['Book Successfully Deleted']); +// +// } +// else{ +// return back()->withErrors( 'OOPS.! Error In Book Deletefirst.'); +// } + return back()->with('success', ['Book Successfully Deleted.']); } catch (\Exception $e) { - return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine()); + return back()->withErrors( 'OOPS.! Error In Book Delete.'); } @@ -75,26 +83,13 @@ public function bookUpdate($data) $bookUpdates = array("name" => $data->name, "price" => $data->price, "author_name" => $data->author_name, "special_price" => $data->special_price, "book_created_date" => $data->book_created_date, "quantity" => $data->quantity); - $result = Book::updateOrCreate($id, $bookUpdates); - - if (!$result) { - throw new Exception("Error in book updateOrCreate"); - } -// $bookUpdate= Book::find($data->update_book_id); -// -// $bookUpdate->name = $data->update_book_name; -// $bookUpdate->price = $data->update_book_price; -// $bookUpdate->author_name = $data->update_book_author_name; -// $bookUpdate->special_price = $data->update_book_special_price; -// $bookUpdate->book_created_date = $data->update_book_created_date; -// $bookUpdate->quantity = $data->update_book_quantity; -// -// return $bookUpdate->save(); + Book::updateOrCreate($id, $bookUpdates); + return back()->with('success', ['Book Successfully Updated.']); } catch (\Exception $e) { - Log::error($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine()); + return back()->withErrors( 'OOPS.! Error In Book Update.'); } @@ -103,35 +98,17 @@ public function bookUpdate($data) // method to get books to admin books view. (to datatable) public function getAPIBooks() { - try { - $getbooks = Book::select('id', 'name', 'price', 'special_price', 'author_name', 'book_created_date', 'quantity'); - - return $getbooks; - - } catch (\Exception $e) { - return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine()); + return Book::select('id', 'name', 'price', 'special_price', 'author_name', 'book_created_date', 'quantity'); - } } // method SUBTRACT the buying quantity from BOOKS table. public function subtractBookQuantity($id) { - try { - - $saveBook = Book::find($id); - - return $saveBook; - -// return Book::updateOrCreate(['quantity' => '$qty'],['id' => '$id']); + return Book::find($id); - } catch (\Exception $e) { - return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine()); - - - } } diff --git a/app/Lib/Crud/BuyBookShopLib.php b/app/Lib/Crud/BuyBookShopLib.php index 85f3937..a9a849b 100644 --- a/app/Lib/Crud/BuyBookShopLib.php +++ b/app/Lib/Crud/BuyBookShopLib.php @@ -37,11 +37,12 @@ public function storeBookAfterBuy($data) $saveBook->quantity = $bookqty - ($buyedbook); - return $saveBook->save(); + $saveBook->save(); + return redirect('buydbooks')->with('success', ['Book purchesed Successfully.']); } catch (\Exception $e) { - return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine()); + return redirect('userbooks')->withErrors( 'OOPS.! Error In purchesing Book.'); } diff --git a/resources/views/admin/adminbooks.php b/resources/views/admin/adminbooks.php index 1749eec..c86a898 100644 --- a/resources/views/admin/adminbooks.php +++ b/resources/views/admin/adminbooks.php @@ -2,6 +2,40 @@ +

+ +"; + + + } + +} + +if ($errors->any()) { + + echo "
+
diff --git a/resources/views/layouts/BootStrapTable.php b/resources/views/layouts/BootStrapTable.php index 302a954..550e613 100644 --- a/resources/views/layouts/BootStrapTable.php +++ b/resources/views/layouts/BootStrapTable.php @@ -493,31 +493,32 @@ function myFunction(split) { "; + + + } + +} + +if ($errors->any()) { + + echo "
    " ; + + foreach ($errors->all() as $error) { + + + echo "

  • ".$error."
  • "; + + + } + +} +?> +
+
+