/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { $bookstatus = \App\BookStatus::find($id); if ($bookstatus) { $rules = \App\BookStatus::$rules; //$rules['name'] = 'required|min:2'; $validator = \Validator::make(\Input::all(), $rules); if ($validator->passes()) { $bookstatus = \App\BookStatus::find($id); $bookstatus->name = \Input::get('name'); $bookstatus->save(); flash('Book Status updated'); return \Redirect::back(); } return \Redirect::back()->withInput()->withErrors($validator); } flash()->error('Book Status does not exist.'); return \Redirect::back(); }
public function isNotAvailable($bookClubId, $bookId) { // dd($this->borrowedBooks()->get()); $statusId = \App\BookStatus::where('name', 'Not Available')->first()->id; if ($this->booksInClubs()->where('book_club_id', $bookClubId)->where('book_id', $bookId)->where('status_id', $statusId)->get()->count()) { return true; } return false; }
public function clubStatus($bookClubId) { $result = []; $statuses = collect(); $bookclubs = $this->bookclubs()->where('book_club_id', $bookClubId)->get()->groupBy('pivot.status_id'); foreach ($bookclubs->toArray() as $key => $value) { $key = \App\BookStatus::findOrFail($key)->name; $statuses->put($key, count($value)); } return $statuses; }
public function changeStatus($bookId, $ownerId, $status) { $statusId = \App\BookStatus::firstOrCreate(['name' => $status])->id; \DB::table('book_book_club')->where('book_club_id', $this->id)->where('book_id', $bookId)->where('owner_id', $ownerId)->update(['status_id' => $statusId]); return true; }
/** * Display the specified resource. * * @param int $id * @return Response */ public function storeBook($bookClubId, Request $request) { $user = auth()->user(); if (!$user->isMember($bookClubId)) { flash()->warning('Please join club first and then add books. '); return redirect()->back(); } $bookclub = \App\BookClub::findOrFail($bookClubId); $status_id = \App\BookStatus::availableId(); $bookIds = $request->input('bookIds'); // dd($request->all()); foreach ($bookIds as $bookId) { if ($user->ownBook($bookId)) { \DB::table('book_book_club')->where('book_club_id', $bookClubId)->where('book_id', $bookId)->where('owner_id', auth()->user()->id)->delete(); $bookclub->books()->attach($bookId, ['status_id' => $status_id, 'owner_id' => auth()->user()->id]); } else { flash()->warning('All books added except those which are not in your library. '); } } flash('Books added successfully.'); return redirect()->back(); }
public function addtolibrary($bookId) { $status_id = \App\BookStatus::availableId(); auth()->user()->books()->attach($bookId, ['status_id' => $status_id]); flash('Book added to library.'); return \Redirect::back(); }