public function prosesAdd() { $pub = new Publisher(); $pub->PublisherName = $_POST['name']; $pub->PublisherAddress = $_POST['address']; $pub->PublisherCity = $_POST['city']; $pub->PublisherPhone = $_POST['phone']; $pub->save(); header("Location: " . base . "/Publisher"); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $result = Validator::make(Input::all(), ['title' => 'required', 'author' => 'required', 'publisher' => 'required', 'isbn' => "required|max:13|min:13|regex:/^[1-9][0-9]{12}\$/"], ['title.required' => 'Book title is required', 'author.required' => 'Book author is required', 'isbn.required' => 'ISBN is required', 'isbn.max' => 'ISBN must be exactly 13 characters', 'isbn.min' => 'ISBN must be exactly 13 characters', 'isbn.regex' => 'ISBN must contain numbers only.', 'publisher.required' => 'Publisher is required']); if ($result->fails()) { $result->errors()->add('submitted', 1); $result->errors()->add('desc', Input::get('description') !== "" ? TRUE : FALSE); return redirect()->route('books.new')->withErrors($result->errors())->withInput(); } $author_id = $request->get('author_id'); if (intval($author_id) == -1) { $new_author = new Author(); $new_author->author_name = $request->get('author'); $new_author->save(); $author_id = $new_author->id; // Create copy of newly created author $new_author = new Author(); $new_author->author_name = $request->get('author'); $new_author->record_id = $author_id; $new_author->save(); } $publisher_id = $request->get('publisher_id'); if (intval($publisher_id) == -1) { $new_publisher = new Publisher(); $new_publisher->name = $request->get('publisher'); $new_publisher->save(); $publisher_id = $new_publisher->id; // Create copy of newly created publisher $new_publisher = new Publisher(); $new_publisher->name = $request->get('publisher'); $new_publisher->record_id = $publisher_id; $new_publisher->save(); } $book = new Books(); $book->title = $request->get("title"); $book->author_id = $author_id; $book->publisher_id = $publisher_id; $book->isbn = $request->get("isbn"); $book->description = $request->get('description'); $book->date_published = $request->get('date_published'); $book->save(); $book_id = $book->id; // Create copy of newly created book $book = new Books(); $book->title = $request->get("title"); $book->author_id = $author_id; $book->publisher_id = $publisher_id; $book->isbn = $request->get("isbn"); $book->description = $request->get('description'); $book->date_published = $request->get('date_published'); $book->record_id = $book_id; $book->save(); return redirect()->route('books.home')->with('status', "New book created"); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { if ($request->get('type') == 'async') { $validator = Validator::make(Input::all(), ['publisher_name' => 'required|min:5'], ['publisher_name.required' => 'Publisher name is required. Publisher not saved.', 'publisher_name.min' => 'Publisher name must be minimum of 5 characters']); if ($validator->fails()) { $return['error'] = $validator->errors(); $return['model'] = ['publisher_name' => FALSE, 'id' => FALSE]; echo json_encode($return); return; } $return['error'] = $validator->errors(); $publisher = new Publisher(); $publisher->name = $request->get('publisher_name'); $publisher->save(); $publisher_id = $publisher->id; $publisher = new Publisher(); $publisher->name = $request->get('publisher_name'); $publisher->record_id = $publisher_id; $publisher->save(); $return['model'] = ['publisher_name' => $request->get('publisher_name'), 'id' => $publisher_id]; echo json_encode($return); return; } }