/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); User::truncate(); Book::truncate(); BookClub::truncate(); Publisher::truncate(); Category::truncate(); Language::truncate(); // $this->call(UserTableSeeder::class); // factory(User::class, 5)->create(); $this->call(UserTableSeeder::class); factory(Book::class, 14)->create(); factory(BookClub::class, 6)->create(); factory(Category::class, 3)->create(); factory(Publisher::class, 3)->create(); factory(Language::class, 3)->create(); DB::table('book_statuses')->insert(['name' => 'Available']); DB::table('book_statuses')->insert(['name' => 'Not Available']); Model::reguard(); }
public function sendBookRequest($bookClubId, $bookId, $userId) { \App\RequestBookClubBook::where('book_club_id', '=', $bookClubId)->where('book_id', '=', $bookId)->where('user_id', '=', auth()->user()->id)->where('owner_id', '=', $userId)->delete(); $bookclub = \App\BookClub::findOrFail($bookClubId); return auth()->user()->bookClubBookRequestsSent()->create(['book_club_id' => $bookClubId, 'book_id' => $bookId, 'owner_id' => $userId]); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function removeBook($bookClubId, $bookId, Request $request) { //check if book is shared $book = \App\Book::findOrFail($bookId); if ($book->isSharedInClub($bookClubId)) { flash()->error('Book is shared with someone. It cannot be removed from bookclub until received back.'); return \Redirect::back(); } $bookclub = \App\BookClub::findOrFail($bookClubId); \DB::table('book_book_club')->where('book_club_id', $bookClubId)->where('book_id', $bookId)->where('owner_id', auth()->user()->id)->delete(); flash('Book removed from club'); return redirect()->back(); }