public function savePublisher(Request $request) { if ($request->publisher_id != "") { $publisher = Publisher::find($request->publisher_id); $publisher->name = $request->name; $publisher->short_intro = $request->short_intro; $check = $publisher->save(); if ($check) { return "EDIT_SUCCEED"; } else { return "Có lỗi xảy ra. Vui lòng thử lại sau!"; } } else { $publisher = new Publisher(); $publisher->name = $request->name; $publisher->country = $request->country; $publisher->short_intro = $request->short_intro; $check = $publisher->save(); if ($check) { $data = array('msg' => 'ADD_SUCCEED', 'publisher_id' => $publisher->id); return $data; } else { return "Có lỗi xảy ra. Vui lòng thử lại sau!"; } } }
public function getBook() { $books = Book::join('genre', 'genre.id', '=', 'book.genre_id')->join('author', 'author.id', '=', 'book.author_id')->join('publisher', 'publisher.id', '=', 'book.publisher_id')->select('book.id', 'title', 'genre_id', 'genre.name as genre_name', 'author_id', 'author.name as author_name', 'publisher_id', 'publisher.name as publisher_name', 'image', 'isbn', 'description_short', 'price', 'sale', 'quantity')->where('book.deleted', '=', 0)->get(); $genres = Genre::where('deleted', '=', 0)->orderBy('name')->get(); $authors = Author::where('deleted', '=', 0)->orderBy('name')->get(); $publishers = Publisher::where('deleted', '=', 0)->orderBy('name')->get(); $data = array('books' => $books, 'authors' => $authors, 'genres' => $genres, 'publishers' => $publishers); return view('admin.pages.book')->with('data', $data); }
public function activities(Request $request) { if (!$this->hasAccess($request)) { return Response()->json(['error' => 'Access denied.'], 500); } if (Gate::denies('update-territories')) { return Response()->json(['error' => 'Method not allowed'], 403); } return ['data' => ['publishers' => Publisher::latest()->count(), 'territories' => Territory::latest()->count(), 'records' => 255]]; }
/** * Get the filters for the territory. */ public static function getFilters($filters) { // userId if (array_key_exists('userId', $filters)) { $publisher = Publisher::where('user_id', $filters['userId'])->first(); if (!empty($publisher['id'])) { return ['publisher_id' => $publisher['id']]; } else { return ['id' => null]; } } }
public function destroy(Request $request) { $validator = Validator::make($request->all(), ['id' => 'required']); if ($validator->fails()) { return Response::json(array('result' => false, 'data' => 'data is valide.')); } $publisher = Publisher::withTrashed()->where('id', $request->input('id'))->get()->first(); if ($publisher != null) { $publisher->forceDelete(); return Response::json(array('result' => true, 'data' => $publisher)); } return Response::json(array('result' => false, 'data' => $publisher)); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store() { $publisher = new Publisher(); $data = Input::all(); $validator = $this->checkValidation(); if ($validator->fails()) { $messages = $validator->messages(); foreach ($messages->all() as $message) { $msg[] = $message; } return $this->errorMessage($msg); } $userDetail = $publisher->getDetailByUserId($data['user_id']); if (empty($userDetail)) { $advertiserProfile = $publisher->insert($data); $msg[] = "Profile saved successfully."; return $this->successMessageWithVar($msg, $advertiserProfile); } else { $advertiserProfile = $publisher->updateData($data); $msg[] = "Profile updated successfully."; return $this->successMessageWithVar($msg, $advertiserProfile); } }
public function insert($data) { $user = new Publisher(); if (isset($data['user_id'])) { $user->user_id = $data['user_id']; } if (isset($data['age'])) { $user->age = $data['age']; } if (isset($data['address'])) { $user->address = $data['address']; } if (isset($data['city'])) { $user->city = $data['city']; } if (isset($data['state'])) { $user->state = $data['state']; } if (isset($data['zip'])) { $user->zip = $data['zip']; } if (isset($data['lat'])) { $user->lat = $data['lat']; } if (isset($data['lng'])) { $user->lng = $data['lng']; } if (isset($data['phone'])) { $user->phone = $data['phone']; } if (isset($data['email'])) { $user->email = $data['email']; } $user->save(); return $user; }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { $publisher = \App\Publisher::find($id); if ($publisher) { $rules = \App\Publisher::$rules; //$rules['name'] = 'required|min:2'; $validator = \Validator::make(\Input::all(), $rules); if ($validator->passes()) { $publisher = \App\Publisher::find($id); $publisher->name = \Input::get('name'); $publisher->save(); flash('Publisher updated'); return \Redirect::back(); } return \Redirect::back()->withInput()->withErrors($validator); } flash()->error('Publisher does not exist.'); return \Redirect::back(); }
/** * Run the database seeds. * * @return void */ public function run() { $edition = array('First edition', 'Second edition', 'Third edition', 'Fourth edition', 'Fifth edition', 'Sixth edition', 'Seventh edition', 'Eighth edition', 'Ninth edition', 'Tenth edition'); $status = array('active', 'inactive'); $publishers = \App\Publisher::getByStatus(\App\Publisher::STATUS_ACTIVE)->get()->toArray(); $workTypes = \App\WorkType::all()->toArray(); for ($i = 0; $i < 50; $i++) { $work = new \App\Work(); $work->title = 'work name ' . $i; $work->publication_year = rand(2000, 2015); $work->edition = $edition[array_rand($edition)]; $work->price = 123.45; $work->isbn = '12345678910' . $i; $work->publisher_id = $publishers[array_rand($publishers)]['id']; $work->work_type_id = $workTypes[array_rand($workTypes)]['id']; $work->status = $status[array_rand($status)]; $work->save(); } }
/** * 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 delete($id) { // Checking if publisher exists $publisher = Publisher::find($id); // If publisher exists if (!empty($publisher)) { // Finding related books $books = $this->booksService->getAllWithPublisher($id); if (!empty($books['data'])) { // Delete related books foreach ($books['data'] as $book) { $this->booksService->delete($book->id); } } // Delete publisher $publisher->delete(); // Returning success message return $this->responseService->returnSuccess(); } else { // Publisher not found // Returning error message return $this->responseService->errorMessage('Publisher was not Found.'); } }
| It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::get('search/getAuthors', 'SearchController@getAuthors'); Route::get('/', 'SearchController@getBooks')->name('home'); //HOME Route::get('/book/create', ['middleware' => 'auth.role:1', function () { $publishers = ['' => ''] + \App\Publisher::lists('publisher', 'id')->all(); $collections = ['' => ''] + \App\Collection::lists('collection', 'id')->all(); $publishers[0] = 'Outros'; return view('book/create', ['publishers' => $publishers, 'collections' => $collections]); }]); Route::get('/book/edit/{id}', ['middleware' => 'auth.role:1', function ($id) { $book = \App\Book::find($id); $publishers = ['' => ''] + \App\Publisher::lists('publisher', 'id')->all(); $collections = ['' => ''] + \App\Collection::lists('collection', 'id')->all(); $publishers[0] = 'Outros'; return view('book/edit', ['book' => $book, 'publishers' => $publishers, 'collections' => $collections]); }]); Route::get('/book/list', ['middleware' => 'auth.role:1', function () { $books = App\Book::where('id_user', '=', Auth::user()->id)->where('active', 1)->get(); return view('book/list', ['books' => $books]); }]); Route::get('/book/return/{id}', ['middleware' => 'auth.role:1', function ($id) { $returns = new App\Returns(); $returns->rental_id = $id; $returns->save(); return back(); }]); Route::get('/book/returnConfirmed/{id}', ['middleware' => 'auth.role:1', function ($id) {
public function addbooks() { header('Content-Type: text/html; charset=utf-8'); for ($i = 0; $i <= 10; $i++) { $user = new User(); $user->name = $this->generateRandomString(5); $user->password = bcrypt($user->name); $user->email = $user->name . '@gmail.com'; $user->save(); } $names = ['%22feliz%20gouveia%22', '%22nuno%20ribeiro%22', '%22jose%20torres%22', '%22borges%20gouveia%22', '%22Sophia%20breyner%22', '%22Fernando%20Pessoa%22', '%22Eça%20De%20Queiros%22']; foreach ($names as $name) { $content = file_get_contents('https://www.googleapis.com/books/v1/volumes?q=' . $name); $content = json_decode($content, true); $auts = Author::all('name'); $authors = array(); foreach ($auts as $aut) { $authors[] = $aut['name']; } $pubs = Publisher::all('publisher'); $publishers = array(); foreach ($pubs as $pub) { $publishers[] = $pub['publisher']; } $cats = Collection::all('collection'); $categories = array(); foreach ($cats as $cat) { $categories[] = $cat['collection']; } foreach ($content['items'] as $data) { $data = $data['volumeInfo']; $book = new Book(); if (isset($data['title'])) { $book->title = $data['title']; } if (isset($data['subtitle'])) { $book->subtitle = $data['subtitle']; } if (isset($data['publishedDate'])) { $book->publishedDate = $data['publishedDate']; } if (isset($data['description'])) { $book->description = $data['description']; } if (isset($data['pageCount'])) { $book->pages = $data['pageCount']; } if (isset($data['language'])) { $book->language = $data['language']; } if (isset($data['industryIdentifiers'])) { foreach ($data['industryIdentifiers'] as $value) { if ($value['type'] == 'ISBN_13') { $book->isbn13 = $value['identifier']; } if ($value['type'] == 'ISBN_10') { $book->isbn10 = $value['identifier']; } } } if (isset($data['publisher'])) { if (!in_array($data['publisher'], $publishers)) { $publishers[] = $data['publisher']; $publisher = new Publisher(); $publisher->publisher = $data['publisher']; $publisher->save(); $publisher_id = $publisher->id; } else { $publisher = Publisher::where('publisher', '=', $data['publisher'])->limit(1)->get(); $publisher_id = $publisher[0]->id; } } if (isset($data['imageLinks']['thumbnail'])) { $book->cover = file_get_contents($data['imageLinks']['thumbnail']); } $book->price_day = random_int(0, 15); $book->price_bail = random_int(10, 50); $book->price_sale = random_int(10, 79); $books[] = $book; $book->id_publisher = $publisher_id; $book->id_user = rand(1, 10); $book->save(); $book_id = $book->id; if (isset($data['categories'])) { foreach ($data['categories'] as $value) { if (!in_array($value, $categories)) { $categories[] = $value; $category = new Collection(); $category->collection = $value; $category->save(); $category_id = $category->id; $collections = new Book_Collection(); $collections->book_id = $book_id; $collections->collection_id = $category_id; $collections->save(); } else { $category = Collection::where('collection', '=', $value)->limit(1)->get(); $collections = new Book_Collection(); $collections->book_id = $book_id; $collections->collection_id = $category[0]->id; $collections->save(); } } } if (isset($data['authors'])) { foreach ($data['authors'] as $value) { if (!in_array($value, $authors)) { $authors[] = $value; $author = new Author(); $author->name = $value; $author->save(); $author_id = $author->id; $author_book = new Author_Book(); $author_book->book_id = $book_id; $author_book->author_id = $author_id; $author_book->save(); } else { $author = Author::where('name', 'like', $value)->limit(1)->get(); $author_book = new Author_Book(); $author_book->book_id = $book_id; $author_book->author_id = $author[0]->id; $author_book->save(); } } } # code... } } }
public function delete(Request $request, $publisherId) { if (!$this->hasAccess($request)) { return Response()->json(['error' => 'Access denied.'], 500); } if (Gate::denies('admin')) { return Response()->json(['error' => 'Method not allowed'], 403); } try { $publisher = Publisher::findOrFail($publisherId); $data = $publisher->delete(); } catch (Exception $e) { $data = ['error' => 'User not found', 'message' => $e->getMessage()]; } return ['data' => $publisher ? true : null]; }
/** * Check if Publisher exists, if yes, return else create new and return * @param $publishers_name * @return static */ private function getPublisher($publishers_name) { return Publisher::firstOrCreate(['name' => $publishers_name]); }
/** * Update the specified resource in storage. * * @param $id * @param LibraryRequest $request * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function update($id, LibraryRequest $request) { $books = Book::findOrFail($id); $bindings = Binding::with('id'); $categories = Categories::with('id'); $conditions = Condition::with('id'); $editions = Edition::with('id'); $publishers = Publisher::with('id'); $rarities = Rarity::with('id'); $signatures = Signature::with('id'); // Availability option switch (on = 1; off = 0) $available = Input::all(); // Special Collection option switch (on = 1; off = 0) $special_collection = Input::all(); // Handle With Care option switch (on = 1; off = 0) $handle_with_care = Input::all(); $books->update($request->all()); Auth::user()->books()->save($books, $bindings, $categories, $conditions, $editions, $publishers, $rarities, $signatures, $available, $special_collection, $handle_with_care); return redirect('admin/library'); }
/* |-------------------------------------------------------------------------- | Model Factories |-------------------------------------------------------------------------- | | Here you may define all of your model factories. Model factories give | you a convenient way to create models for testing and seeding your | database. Just tell the factory how a default model should look. | */ $factory->define(App\User::class, function (Faker\Generator $faker) { return ['name' => $faker->name, 'email' => $faker->email, 'password' => bcrypt('default')]; }); $factory->define(App\Author::class, function (Faker\Generator $faker) { $status = array('active', 'inactive'); return ['name' => $faker->name, 'status' => $status[array_rand($status)]]; }); $factory->define(App\WorkType::class, function (Faker\Generator $faker) { return ['description' => $faker->word]; }); $factory->define(App\Publisher::class, function (Faker\Generator $faker) { $status = array('active', 'inactive'); return ['name' => $faker->name, 'status' => $status[array_rand($status)]]; }); $factory->define(App\Work::class, function (Faker\Generator $faker) { $edition = array('First edition', 'Second edition', 'Third edition', 'Fourth edition', 'Fifth edition', 'Sixth edition', 'Seventh edition', 'Eighth edition', 'Ninth edition', 'Tenth edition'); $status = array('active', 'inactive'); $publishers = \App\Publisher::getByStatus(\App\Publisher::STATUS_ACTIVE)->get()->toArray(); $workTypes = \App\WorkType::all()->toArray(); return ['title' => $faker->name, 'publication_year' => rand(2000, 2015), 'edition' => $edition[array_rand($edition)], 'price' => 102.15, 'isbn' => $faker->isbn13, 'publisher_id' => $publishers[array_rand($publishers)]['id'], 'work_type_id' => $workTypes[array_rand($workTypes)]['id'], 'status' => $status[array_rand($status)]]; });
| database. Just tell the factory how a default model should look. | */ $factory->define(App\User::class, function ($faker) { return ['name' => $faker->name, 'email' => $faker->email, 'password' => str_random(10), 'remember_token' => str_random(10)]; }); $factory->define(App\Author::class, function ($faker) { $romaji = $faker->name; $faker = \Faker\Factory::create('ja_JP'); return ['name' => $faker->name, 'furigana' => $faker->kananame, 'romaji' => $romaji]; }); $factory->define(App\Phone::class, function ($faker) { $faker = \Faker\Factory::create('ja_JP'); return ['phone' => $faker->phoneNumber]; }); $factory->define(App\Publisher::class, function ($faker) { $faker_jp = \Faker\Factory::create('ja_JP'); return ['name' => $faker_jp->company . '出版', 'furigana' => $faker_jp->lastKanaName . 'シュッパン', 'romaji' => $faker->company]; }); $factory->define(App\Book::class, function ($faker) { $faker = \Faker\Factory::create('ja_JP'); return ['isbn' => $faker->isbn13, 'title' => '書籍名', 'price' => rand(450, 15000), 'published_date' => $faker->date(), 'pages' => rand(50, 600), 'author_id' => \App\Author::get()->random()->id, 'publisher_id' => \App\Publisher::get()->random()->id]; }); $factory->define(App\Dvd::class, function ($faker) { $faker = \Faker\Factory::create('ja_JP'); return ['isbn' => $faker->isbn13, 'title' => 'DVDタイトル', 'price' => rand(450, 15000), 'published_date' => $faker->date(), 'time' => rand(5, 180), 'author_id' => \App\Author::get()->random()->id, 'publisher_id' => \App\Publisher::get()->random()->id]; }); $factory->define(App\AuthorType::class, function ($faker) { $faker = \Faker\Factory::create('ja_JP'); return ['name' => $faker->word]; });
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id, Request $request) { $book = \App\Book::findOrFail($id); // $book->update(\Input::all()); // return \Redirect::back()->with('message','Book updated.'); // if($book){ // $rules = \App\Book::$rules; //$rules['name'] = 'required|min:2'; // $validator = \Validator::make(\Input::all(), $rules); // if($validator->passes()) // { $book->description = $request->description; $book->publisher_id = \App\Publisher::firstOrCreate(['name' => ucfirst($request->publisher)])->id; $book->category_id = \App\Category::firstOrCreate(['name' => ucfirst($request->category)])->id; $book->language_id = \App\Language::firstOrCreate(['name' => ucfirst($request->language)])->id; $book->release_date = $request->release_date; $book->save(); //going over author names build up array of author ids by getting author ids and creating author if does not exist $authorIds = []; $authors = $request->authors; if ($authors) { foreach ($authors as $author) { $authorIds[] = App\Author::firstOrCreate(['name' => ucfirst($author)])->id; } //atached book to authors $book->authors()->sync($authorIds); // $book->authors()->attach($authorIds); } if ($request->hasFile('image')) { $this->setBookImage($book, $request); } flash('Book updated.'); return \Redirect::back(); // } // return \Redirect::back() // //->with('message','There were some errors. Please try again later..') // ->withInput() // ->withErrors($validator); // } // // flash()->error('Book does not exist.'); // return \Redirect::back(); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit() { $user_id = Auth::user()->id; $data = INPUT::all(); $rules = $this->rules(); $messages = $this->messages(); $validator = Validator::make($data, $rules, $messages); if (!$validator->fails()) { $book = Book::find($data['id']); $book->title = $data['title']; $book->subtitle = $data['subtitle']; $book->publishedDate = $data['publishedDate']; $book->description = $data['description']; $book->pages = $data['pages']; $book->isbn10 = $data['isbn10']; $book->isbn13 = $data['isbn13']; $book->price_day = $data['price_day']; $book->price_bail = $data['price_bail']; $book->price_sale = $data['price_sale']; $book->language = $data['language']; if ($data['publisher'] != $book->id_publisher) { if ($data['publisher'] != '0') { $book->id_publisher = $data['publisher']; } else { $publisher = new Publisher(); $publisher->publisher = $data['newpublisher']; $publisher->save(); $book->id_publisher = $publisher->id; } } if (isset($data['cover'])) { $book->cover = file_get_contents($data['cover']); } $book_id = $book->id; Book_Collection::where('book_id', $book_id)->delete(); Author_Book::where('book_id', $book_id)->delete(); $book_collection = new Book_Collection(); $book_collection->book_id = $book_id; $book_collection->collection_id = $data['collection']; $authors = explode(',', $data['authors']); foreach ($authors as $author) { $tmp = Author::where('name', 'like', $author)->limit(1)->get(); if (count($tmp) > 0) { $author_book = new Author_Book(); $author_book->book_id = $book_id; $author_book->author_id = $tmp[0]->id; $author_book->save(); } else { $newAuthor = new Author(); $newAuthor->name = $author; $newAuthor->save(); $author_id = $newAuthor->id; $author_book = new Author_Book(); $author_book->book_id = $book_id; $author_book->author_id = $author_id; $author_book->save(); } } $book->save(); return redirect('book/edit/' . $book_id . ''); } return back()->withInput($data)->withErrors($validator); }
public function publisher() { if (Request::ajax()) { $data = Request::get('data'); $sort = Request::get('sort'); $list = Request::get('list'); switch ($data) { case 'pp': $source = Publisher::find($list); $source_book = Book::where('publisher_id', $list)->get(); return view('front.partials.list_item_pp_nxb', ['data' => $source, 'author_book' => $source_book]); case 'word': $source = Publisher::where('name', 'LIKE', $list . '%'); return view('front.partials.list_item_word', ['data' => $source->paginate(9), 'word' => $list]); default: $sources = DB::table('publishers'); $source = HomeController::sort($sources, $sort); return view('front.partials.list_item_all', ['data' => $source->paginate(9)]); } } $source_list = Publisher::orderBy('name', 'ASC')->paginate(9); $source_word = Publisher::select(DB::raw('substr(name,1,1) as alpha'))->groupBy(DB::raw('substr(name,1,1)'))->get(); return view('front.nxb', ['author_word' => $source_word, 'data' => $source_list, 'name_page' => 'Nhà xuất bản', 'table_name' => 'Publishers']); }
/** * @return array */ private function arrayForList() { $authorsArr = Author::select(DB::raw("CONCAT(firstname,' ', lastname) AS fullname, id"))->lists('fullname', 'id'); $publishersArr = Publisher::all()->lists('name', 'id'); return array($authorsArr, $publishersArr); }