Пример #1
0
 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!";
         }
     }
 }
Пример #2
0
 /**
  * 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();
 }
Пример #3
0
 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.');
     }
 }
Пример #4
0
 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']);
 }