当前位置: 首页>>代码示例>>PHP>>正文


PHP Book::create方法代码示例

本文整理汇总了PHP中app\models\Book::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::create方法的具体用法?PHP Book::create怎么用?PHP Book::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Book的用法示例。


在下文中一共展示了Book::create方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: store

 public function store(Request $request)
 {
     $input = $request->all();
     $input['user_id'] = auth()->user()->id;
     Book::create($input);
     return redirect()->route('admin.books.index');
 }
开发者ID:phelipperibeiro,项目名称:book_store_laravel,代码行数:7,代码来源:BooksController.php

示例2: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('books')->truncate();
     $faker = \Faker\Factory::create();
     for ($count = 0; $count < 500; $count++) {
         Book::create(['title' => $faker->sentence(), 'desc' => $faker->text(), 'cover' => $faker->imageUrl()]);
     }
 }
开发者ID:aphiwadChhoeun,项目名称:Book-API,代码行数:13,代码来源:BookTableSeeder.php

示例3: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS = 0');
     Book::truncate();
     $faker = Faker::create();
     for ($i = 1; $i <= 30; $i++) {
         Book::create(['title' => $faker->sentence(), 'description' => $faker->sentence(), 'author' => $faker->name]);
     }
 }
开发者ID:kongtoonarmy,项目名称:laravel-transformers,代码行数:15,代码来源:BooksTableSeeder.php

示例4: create

 public function create($request)
 {
     \DB::beginTransaction();
     $user = \Auth::user();
     $book = Book::create($request->all());
     $book->product()->create($request->all());
     $book->product->organizations()->attach($user->organization->id, ['dewey_code' => $request['dewey_code'], 'quantity' => $request['quantity'], 'cat_id' => $request['cat_id'], 'user_id' => $user->id, 'edited_by' => $user->id]);
     $book->authors()->attach($request['author-list']);
     $item = Item::find($book->product->orgcreate()->first()->pivot->id);
     $item->tags()->attach($request['tag-list']);
     \DB::commit();
 }
开发者ID:nicsmyrn,项目名称:library,代码行数:12,代码来源:DbBookRepository.php

示例5: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $tolkien = Author::create(['name' => 'J.R.R. Tolkien', 'date_of_birth' => '1892-01-03']);
     Book::create(['title' => 'The Hobbit', 'publication_date' => '1937-09-21', 'isbn' => '9780582186552', 'author_id' => $tolkien->id]);
     Book::create(['title' => 'The Silmarillion', 'publication_date' => '1977-09-15', 'isbn' => '9780345325815', 'author_id' => $tolkien->id]);
     $karpyshyn = Author::create(['name' => 'Drew Karpyshyn', 'date_of_birth' => '1971-07-28']);
     Book::create(['title' => 'The Old Republic: Revan', 'publication_date' => '2011-11-15', 'isbn' => '9780857689009', 'author_id' => $karpyshyn->id]);
     Book::create(['title' => 'The Old Republic: Annihilation', 'publication_date' => '2012-11-13', 'isbn' => '9780345529411', 'author_id' => $karpyshyn->id]);
     $salvatore = Author::create(['name' => 'R.A. Salvatore', 'date_of_birth' => '1959-01-20']);
     Book::create(['title' => 'Homeland', 'publication_date' => '2004-03-01', 'isbn' => '9780786931231', 'author_id' => $salvatore->id]);
     Book::create(['title' => 'Attack of the Clones', 'publication_date' => '2003-04-01', 'isbn' => '9780345428820', 'author_id' => $salvatore->id]);
 }
开发者ID:simonbacquie,项目名称:get-started-with-lumen,代码行数:17,代码来源:SampleDataSeeder.php

示例6: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['title' => 'required|string|max:255', 'author' => 'required|string|max:255', 'barcode' => 'required|string|max:255', 'name' => 'required|string|max:255', 'email' => 'required|email|max:255']);
     try {
         $book = Book::create($request->all());
         $book->status = 'borrowed';
         $book->borrowed_at = new \DateTime();
         $book->save();
     } catch (\Exception $e) {
         return redirect()->back()->withErrors(['An unknown error has occurred while attempting to save this record']);
     }
     return redirect(action('BookController@index'))->with('success', ['The record was successfully saved']);
 }
开发者ID:simple-peacock,项目名称:bookshelf,代码行数:19,代码来源:BookController.php

示例7: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     //Validate the Request
     $this->validate($request, ['title' => 'required', 'subject_id' => 'required|numeric', 'coverImage' => 'image', 'book' => 'mimes:pdf']);
     $request['uploaded_by'] = Auth::user()->id;
     if ($request->hasFile('coverImage')) {
         $imageName = str_slug($request['title']) . '_' . Auth::user()->id . '.' . $request['coverImage']->getClientOriginalExtension();
         $location = 'uploads/Books/' . $request['subject_name'] . '/' . $request['title'] . '/';
         $request['coverImage']->move($location, $imageName);
         $imageUrl = url($location . $imageName);
         $request['image'] = $imageUrl;
     }
     if ($request->hasFile('book')) {
         $bookName = str_slug($request['title']) . '.' . $request['book']->getClientOriginalExtension();
         $location = 'uploads/Books/' . $request['subject_name'] . '/' . $request['title'] . '/';
         $request['book']->move($location, $bookName);
         $bookUrl = url($location . $bookName);
         $request['book_url'] = $bookUrl;
     }
     Book::create($request->all());
     \Session::flash('flash_message', 'Book Created Successfully!');
     \Session::flash('flash_message_level', 'success');
     return Redirect::back();
 }
开发者ID:razikallayi,项目名称:peaceschools,代码行数:30,代码来源:LibraryController.php

示例8: addNewBook

 /**
  * Add new book to database.
  * @param [array] $data array data from request
  * @return [type]  $book object book model which has just created
  */
 public function addNewBook($data)
 {
     $book = Book::create(['title' => $data['title'], 'bookurl' => $data['bookurl'], 'language_id' => 1, 'avatar' => 'question-mark.png', 'diravatar' => 'question-mark.png']);
     DB::table('book_author')->insert(['book_id' => $book->id, 'author_id' => Auth::user()->id, 'is_main' => 1, 'is_accepted' => 1]);
     Price::create(['item_id' => 'bo|' . $book->id, 'minimumprice' => 0, 'suggestedprice' => 0]);
     return $book;
 }
开发者ID:phanngoc,项目名称:elearnpub,代码行数:12,代码来源:Book.php

示例9: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['book_title' => 'required|string|max:500|unique:books,title', 'book_author_name' => 'required|string', 'book_nb_pages' => 'required|integer']);
     $book = Book::create(['title' => $request->input('book_title'), 'author' => $request->input('book_author_name'), 'num_pages' => $request->input('book_nb_pages')]);
     return response(['book' => $book], 201)->header('Location', '/api/books/' . $book->id);
 }
开发者ID:jrm2k6,项目名称:i-heart-reading,代码行数:12,代码来源:BooksController.php

示例10: createBook

 /**
  * Show the application dashboard to the user.
  *
  * @return Response
  */
 public function createBook(StoreBookPostRequest $request)
 {
     if (Input::hasFile('download_link')) {
         // upload path
         $destinationPath = 'uploads/';
         $download_link = Input::file('download_link');
         // renameing image
         $fileName = rand(11111, 99999) . '-' . $download_link->getClientOriginalName();
         $download_link->move($destinationPath, $fileName);
     }
     if ($book_id = Input::get('book_id')) {
         $book = Book::find($book_id);
         $book->book_name = Input::get('book_name');
         $book->book_slug = str_slug(Input::get('book_name'), '-');
         $book->author = Input::get('author');
         $book->publication = Input::get('publication');
         $book->description = Input::get('description');
         $book->rate = Input::get('rate');
         $book->discount = Input::get('discount');
         $book->discount_qty = Input::get('discount_qty');
         $book->book_type_id = Input::get('book_type_id');
         $book->category_id = Input::get('category_id');
         if (Input::hasFile('download_link')) {
             $book->download_link = $destinationPath . $fileName;
         }
         $book->show_home_page = Input::get('show_home_page');
         $book->save();
         $success = 'Book updated successfully';
     } else {
         $book = Input::get();
         $book['book_slug'] = str_slug(Input::get('book_name'));
         $book['download_link'] = $destinationPath . $fileName;
         Book::create($book);
         $success = 'Book created successfully';
     }
     return redirect('admin/book/dashboard')->with('success', $success);
 }
开发者ID:nandha007,项目名称:tnbooks.in,代码行数:42,代码来源:AdminController.php


注:本文中的app\models\Book::create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。