本文整理汇总了PHP中app\Book::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::save方法的具体用法?PHP Book::save怎么用?PHP Book::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Book
的用法示例。
在下文中一共展示了Book::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
$user_id = Auth::user()->id;
$data = INPUT::all();
$rules = $this->rules();
$messages = $this->messages();
$validator = Validator::make($data, $rules, $messages);
if (!$validator->fails()) {
$book = new Book();
$book->id_user = $user_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'] != '0') {
$book->id_publisher = $data['publisher'];
} else {
$publisher = new Publisher();
$publisher->publisher = $data['newpublisher'];
$publisher->save();
$book->id_publisher = $publisher->id;
}
$book->cover = file_get_contents($data['cover']);
$book->save();
$book_id = $book->id;
$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();
}
}
return redirect('book/show/' . $book_id . '');
} else {
return back()->withInput($data)->withErrors($validator);
}
}
示例2: Book
function getExample4()
{
//CREATE
$book = new Book();
$book->title = 'Harry Potter';
$book->author = 'J.K.Rowling';
$book->save();
return 'example 4';
}
示例3: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(BookRegistrationRequest $request)
{
$book = new Book();
$book->title = $request->title;
$book->author = $request->author;
$book->language = $request->language;
$book->publication_date = $request->publication_date;
$book->save();
return new JsonResponse(['msg' => 'OK', 'id' => $book->id], 201);
}
示例4: testProcessBookShow
/**
*
* Tests the module showing details of a single book is working by first adding a new book
* and matching the data inserted vs data seen.
*
*/
public function testProcessBookShow()
{
//create a book
$book = new Book();
$book->title = 'The Hobbit';
$book->author = 'Tolkien';
$book->save();
//see if the created book shows the same details used earlier
$bookShowURL = '/books/' . $book->id;
$this->visit($bookShowURL)->see('Tolkien')->see('The Hobbit');
}
示例5: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$book = new Book();
$book->name = $request->name;
$book->product_code = $request->product_code;
$book->kStatus = $request->kStatus;
$book->authors = $request->authors;
$book->description = $request->description;
$book->price = $request->price;
$book->user_id = Auth::user()->id;
$book->save();
return redirect()->route('book.index');
}
示例6: run
public function run()
{
DB::table('books')->truncate();
for ($i = 0; $i < 10; $i++) {
$book = new Book();
$book->book_name = str_random(10);
$book->book_auther = str_random(10);
$book->book_press = str_random(10);
$book->book_num = 10;
$book->book_res = 10;
$book->save();
}
}
示例7: store
public function store(Request $request)
{
$this->validate($request, ['bk_isbn' => 'required|max:225', 'bk_title' => 'required|max:225', 'bk_author' => 'required|max:225', 'bk_publisher' => 'required|max:225', 'bk_count' => 'required|integer']);
$books = new Book();
$books->bk_isbn = $request->bk_isbn;
$books->bk_title = $request->bk_title;
$books->bk_author = $request->bk_author;
$books->bk_publisher = $request->bk_publisher;
$books->bk_count = $request->bk_count;
$books->bk_desc = $request->bk_desc;
$books->save();
return redirect('books');
}
示例8: postAddbook
public function postAddbook(Request $request)
{
$this->validate($request, ['bookname' => 'required|max:200', 'author' => 'max:50', 'count' => 'required|integer', 'introduction' => 'string']);
$book = new Book();
$book->bookname = $request->input('bookname');
$book->count = $request->input('count');
$book->author = $request->input('author');
$book->introduction = $request->input('introduction');
$book->user_id = Auth::user()->id;
if (!$book->save()) {
return Redirect::back()->withErrors('数据无法被存储,请重新提交!');
}
return Redirect::back()->withErrors('数据提交成功!');
}
示例9: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(BookRequest $request)
{
if (Input::file('cover')->isValid()) {
$file = Input::file('cover');
$destinationPath = 'images/cover';
$fileName = rand(11111, 99999) . '_' . $file->getClientOriginalName();
Input::file('cover')->move($destinationPath, $fileName);
$data = new Book();
$data->fill($request->all());
$data->cover = $fileName;
$data->save();
return Redirect('admin/books')->with('successMessage', 'Berhasil menambah buku.');
} else {
return Redirect()->back();
}
}
示例10: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$this->validate($request, ['name' => 'required']);
$book = new Book();
$book->shortname = $request->shortname;
$book->name = $request->name;
$book->pack = $request->pack;
$book->bookgroup_id = $request->bookgroup_id ?: null;
$book->book_type = $request->book_type;
$book->price_buy = $request->price_buy;
$book->price = $request->price;
$book->price_shop = $request->price_shop;
$book->user_id = Auth::user()->id;
$book->save();
return redirect()->route('books.index');
}
示例11: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
$rules = array('title' => 'required', 'author' => 'required|alpha', 'year' => 'required|numeric', 'genre' => 'required|alpha');
$validator = Validator::make($request->all(), $rules);
if ($validator->fails()) {
return Response::json($validator->messages(), 500);
} else {
$book = new Book();
$book->title = $request->title;
$book->author = $request->author;
$book->year = $request->year;
$book->genre = $request->genre;
$book->save();
Session::flash('message', 'New book successfully created');
return Response::json($book);
}
}
示例12: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
$data = array('errNum' => 0, 'errMsg' => '', 'errDate' => '');
$book = new Book();
$book->book_name = $request->book_name;
$book->book_auther = $request->book_auther ? $request->book_auther : "";
$book->book_press = $request->book_press ? $request->book_press : "";
$book->book_num = $request->book_num;
$book->book_res = $request->book_res;
if ($book->save()) {
$data['errMsg'] = "添加成功";
return json_encode($data);
} else {
$data['errMsg'] = "添加失败";
return json_encode($data);
}
}
示例13: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$rules = array('title' => 'required', 'author' => 'required|regex:/^([A-Za-z]+)$/', 'year' => 'required|numeric', 'genre' => 'required|regex:/^([A-Za-z]+)$/');
$validator = Validator::make($request->all(), $rules);
if ($validator->fails()) {
return Redirect::to('book/create')->withErrors($validator)->withInput();
} else {
$book = new Book();
$book->title = $request->title;
$book->author = $request->author;
$book->year = $request->year;
$book->genre = $request->genre;
$book->save();
Session::flash('message', 'Successfully created book');
return Redirect::to('book');
}
}
示例14: saveBook
public function saveBook(Request $request)
{
if ($request->book_id != "") {
$book = Book::find($request->book_id);
$book->title = $request->title;
$book->genre_id = $request->genre_id;
$book->author_id = $request->author_id;
$book->publisher_id = $request->publisher_id;
$book->image = $request->image;
$book->isbn = $request->isbn;
$book->description_short = $request->description_short;
$book->description = $request->description;
$book->price = $request->price;
$book->sale = $request->sale;
$book->quantity = $request->quantity;
$check = $book->save();
if ($check) {
return "EDIT_SUCCEED";
} else {
return "Có lỗi xảy ra. Vui lòng thử lại sau!";
}
} else {
$book = new Book();
$book->title = $request->title;
$book->genre_id = $request->genre_id;
$book->author_id = $request->author_id;
$book->publisher_id = $request->publisher_id;
$book->image = $request->image;
$book->isbn = $request->isbn;
$book->description_short = $request->description_short;
$book->description = $request->description;
$book->price = $request->price;
$book->sale = $request->sale;
$book->quantity = $request->quantity;
$check = $book->save();
if ($check) {
$genre_name = Genre::find($request->genre_id)->name;
$author_name = Author::find($request->author_id)->name;
$data = array('msg' => 'ADD_SUCCEED', 'book_id' => $book->id, 'genre_name' => $genre_name, 'author_name' => $author_name);
return $data;
} else {
return "Có lỗi xảy ra. Vui lòng thử lại sau!";
}
}
}
示例15: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
$rules = array('title' => 'required', 'author' => 'required|alpha', 'year' => 'required|numeric', 'genre' => 'required|alpha');
$validator = Validator::make($request->all(), $rules);
if ($validator->fails()) {
return Redirect::to('books/create')->withErrors($validator)->withInput();
} else {
$book = new Book();
$book->title = $request->title;
$book->author = $request->author;
$book->year = $request->year;
$book->genre = $request->genre;
$book->save();
Session::flash('message', 'New book successfully created');
$job = new Jobs\SendAddNewBookEmail($book);
$this->dispatch($job);
return Redirect::to('books');
}
}