當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Book::create方法代碼示例

本文整理匯總了PHP中Book::create方法的典型用法代碼示例。如果您正苦於以下問題:PHP Book::create方法的具體用法?PHP Book::create怎麽用?PHP Book::create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Book的用法示例。


在下文中一共展示了Book::create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: test_update_from_array

 public function test_update_from_array()
 {
     $data = array('title' => 'New Book', 'author_id' => '1', 'quantity' => '500', 'price' => '7.77');
     // Create Book to test
     $new_book = new Book();
     $new_book->create($data);
     // 'New Book' exists
     // i.e. test may be invalid
     $book = new Book();
     $book = $book->find_by_title('New Book');
     if (count($book) == 0) {
         $this->errors['update_from_array'][] = 'non-existent';
     }
     if (count($book) > 1) {
         $this->errors['update_from_array'][] = 'too_many';
     }
     $new_data = array('author_id' => '2', 'quantity' => '600', 'price' => '8.88');
     $update_book = new Book();
     $update_book = $update_book->first_by_title('New Book');
     $update_book->update($new_data);
     // Fetch book
     // e.g. update() isn't working
     $fetch_book = new Book();
     $fetch_book = $fetch_book->first_by_title('New Book');
     if ($fetch_book->author_id != 2) {
         $this->errors['update_from_array'][] = 'author_id';
     }
     if ($fetch_book->quantity != 600) {
         $this->errors['update_from_array'][] = 'quantity';
     }
     if ($fetch_book->price != '8.88') {
         $this->errors['update_from_array'][] = 'price';
     }
 }
開發者ID:TheOddLinguist,項目名稱:toolbox,代碼行數:34,代碼來源:tester.norm.update.php

示例2: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $image = Input::file('image');
     $filename = time() . '.' . $image->getClientOriginalExtension();
     $path = public_path('uploads/img/' . $filename);
     Image::make($image->getRealPath())->resize(200, 200)->save($path);
     $user->image = $filename;
     $user->save();
     $obj = new helpers();
     echo "<pre>";
     print_r(Input::file('image'));
     exit;
     $book = Request::all();
     //echo "<pre>";print_r($_FILES['image']['name']);exit;
     $destinationPath = 'uploads/img/';
     // upload path
     $thumb_path = 'uploads/img/thumb/';
     $extension = Input::file('image')->getClientOriginalExtension();
     // getting image extension
     $fileName = rand(111111111, 999999999) . '.' . $extension;
     // renameing image
     Input::file('image')->move($destinationPath, $fileName);
     // uploading file to given path
     $obj->createThumbnail($fileName, 300, 200, $destinationPath, $thumb_path);
     $book['image'] = $fileName;
     Book::create($book);
     Session::flash('success', 'Upload successfully');
     return redirect('image');
 }
開發者ID:amittier5,項目名稱:miramix,代碼行數:35,代碼來源:MyController.php

示例3: test_create_from_array

 public function test_create_from_array()
 {
     $data = array('title' => 'New Book', 'author_id' => '1', 'quantity' => '500', 'price' => '7.77');
     // 'New Book' doesn't exist
     // i.e. test may be invalid
     $book = new Book();
     $book = $book->find_by_title('New Book');
     if (count($book) != 0) {
         $this->errors['create_from_array'][] = 'pre-exists';
     }
     $new_book = new Book();
     $new_book->create($data);
     // 'New Book' was created
     // e.g. create() isn't working
     if (is_null($new_book->id)) {
         $this->errors['create_from_array'][] = 'new_book_id';
     }
     // 'New Book' can be fetched
     // e.g. update() isn't working
     $fetch_book = new Book();
     $fetch_book = $fetch_book->find_by_title('New Book');
     if (count($fetch_book) != 1) {
         $this->errors['create_from_array'][] = 'fetch_count';
     }
     if ($fetch_book[0]->id != $new_book->id) {
         $this->errors['create_from_array'][] = 'fetch_id_match';
     }
 }
開發者ID:TheOddLinguist,項目名稱:toolbox,代碼行數:28,代碼來源:tester.norm.create.php

示例4: run

 public function run()
 {
     DB::table('books')->delete();
     Book::create(['title' => 'Requim', 'isbn' => '123', 'price' => '13.40', 'cover' => 'requim.jpg', 'author_id' => 1]);
     Book::create(['title' => 'Twilight', 'isbn' => '456', 'price' => '15.40', 'cover' => 'twilight.jpg', 'author_id' => 2]);
     Book::create(['title' => 'Deception Point', 'isbn' => '789', 'price' => '16.40', 'cover' => 'deception.jpg', 'author_id' => 3]);
 }
開發者ID:ngeshlew,項目名稱:laravel-e-commerce-book-store,代碼行數:7,代碼來源:BooksTableSeeder.php

示例5: run

 public function run()
 {
     DB::table('books')->delete();
     Book::create(array('title' => 'Requiem', 'isbn' => '9780062014535', 'price' => '13.40', 'cover' => 'requiem.jpg', 'author_id' => 1));
     Book::create(array('title' => 'Twilight', 'isbn' => '9780316015844', 'price' => '15.40', 'cover' => 'twilight.jpg', 'author_id' => 1));
     Book::create(array('title' => 'Deception Point', 'isbn' => '9780671027384', 'price' => '16.40', 'cover' => 'deception.jpg', 'author_id' => 3));
 }
開發者ID:jgbneatdesign,項目名稱:kg,代碼行數:7,代碼來源:BooksTableSeeder.php

示例6: run

 public function run()
 {
     $faker = Faker::create();
     Book::truncate();
     foreach (range(1, 30) as $index) {
         Book::create(['title' => $faker->sentence(6), 'author_id' => $faker->randomNumber(1, 5), 'amount' => $faker->randomNumber(1)]);
     }
 }
開發者ID:ryanda,項目名稱:larapus,代碼行數:8,代碼來源:BooksTableSeeder.php

示例7: run

 public function run()
 {
     DB::table('DEMO_Book')->delete();
     Book::create(array('name' => 'Into the Wild', 'author' => 'Jon Krakauer', 'publisher' => 'Pan; New Ed edition (July 6, 2011)', 'language' => 'E', 'length' => 228, 'asin' => 'B005AV93JI', 'description' => 'By examining the true story of Chris McCandless, a young man, who in 1992 walked deep into the Alaskan wilderness and whose SOS note and emaciated corpse were found four months later.'));
     Book::create(array('name' => 'El Príncipe', 'author' => 'Nicolás Maquiavelo', 'publisher' => ' e-artnow ediciones (August 1, 2013)', 'language' => 'S', 'length' => 86, 'asin' => 'B00IORCCMU', 'description' => 'El Príncipe es un tratado de teoría política escrito por Nicolás Maquiavelo en 1513, mientras se encontraba confinado en San Casciano por la acusación de haber conspirado en contra de los Médici.'));
     Book::create(array('name' => 'Twenty Thousand Leagues Under the Sea', 'author' => 'Jules Verne', 'publisher' => 'CreateSpace Independent Publishing Platform (May 22, 2014)', 'language' => 'E', 'length' => 212, 'asin' => '1499637632', 'description' => 'It tells the story of Captain Nemo and his submarine Nautilus, as seen from the perspective of Professor Pierre Aronnax after he, his servant Conseil, and Canadian harpoonist Ned Land wash up on their ship.'));
     Book::create(array('name' => 'In a Sunburned Country', 'author' => 'Bill Bryson', 'publisher' => 'Broadway Books; 1st edition (April 27, 2008)', 'language' => 'E', 'length' => 304, 'asin' => 'B000Q9ISSQ', 'description' => ' In A Sunburned Country is his report on what he found in an entirely different place: Australia, the country that doubles as a continent, and a place with the friendliest inhabitants, the hottest and driest weather.'));
     Book::create(array('name' => 'Das Böse im Verborgenen', 'author' => 'James Oswald', 'publisher' => 'Goldmann Verlag (June 23, 2014)', 'language' => 'G', 'length' => 44, 'asin' => 'B00L2884R0', 'description' => 'Der grandiose Start der Krimi-Reihe um Detective Inspector Anthony McLean'));
 }
開發者ID:chappyhome,項目名稱:laravel-jqgrid-tutorial,代碼行數:9,代碼來源:BookTableSeeder.php

示例8: create

 public function create()
 {
     $_action = 'create';
     $name = Input::get('new_book_name');
     $name = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $name);
     $urlname = str_replace(' ', '-', $name);
     $newbook = Book::create(array('name' => $name, 'urlname' => $urlname, 'traveler_id' => Auth::user()->id, 'created' => date('Y-m-d H:i:s')));
     return Redirect::to('/me');
 }
開發者ID:spark942,項目名稱:supinternet-projects,代碼行數:9,代碼來源:BookController.php

示例9: store

 public function store(bookRequest $request)
 {
     $book = Book::create($request->all());
     if ($request->image) {
         $name = $request->file('image')->getClientOriginalExtension();
         $name = $book->id . '.' . $name;
         $request->file('image')->move('images', $name);
         $book->update(['image' => 'images/' . $name]);
     }
     return redirect('book');
 }
開發者ID:KirillosLeg,項目名稱:new,代碼行數:11,代碼來源:BooksController.php

示例10: run

 public function run()
 {
     $categories = array('Cat1', 'Cat2', 'Cat3');
     $faker = Faker\Factory::create();
     DB::table('books')->delete();
     for ($i = 0; $i < 10; $i++) {
         Book::create(array('isbn' => $faker->ean13(), 'title' => $faker->sentence($nbWords = 3), 'author' => $faker->name(), 'category' => $faker->randomElement($categories), 'publishing_house' => $faker->word(), 'page_no' => $faker->numerify('###'), 'publishing_year' => $faker->year()));
     }
     Book::create(array('isbn' => $faker->ean13(), 'title' => $faker->sentence($nbWords = 3), 'author' => "Murat Memalla", 'category' => $faker->randomElement($categories), 'publishing_house' => $faker->word(), 'page_no' => $faker->numerify('###'), 'publishing_year' => $faker->year()));
     Book::create(array('isbn' => $faker->ean13(), 'title' => $faker->sentence($nbWords = 3), 'author' => "Murat Memalla", 'category' => $faker->randomElement($categories), 'publishing_house' => $faker->word(), 'page_no' => $faker->numerify('###'), 'publishing_year' => $faker->year()));
 }
開發者ID:balliuera,項目名稱:Book_io,代碼行數:11,代碼來源:DatabaseSeeder.php

示例11: create

 public function create()
 {
     Log::debug(__METHOD__);
     $bookName = Input::get('book_name');
     $filter = Input::get('filter');
     $book = Book::whereUserId(Auth::user()->id)->whereName($bookName)->first();
     if (is_null($book)) {
         $book = Book::create(['user_id' => Auth::user()->id, 'name' => $bookName]);
     }
     Session::put('book_id', $book->id);
     return $this->renderCurrentBook($filter);
 }
開發者ID:neilmillard,項目名稱:kanbanlist,代碼行數:12,代碼來源:BooksController.php

示例12: book_create_form_submit

function book_create_form_submit($data)
{
    $error = book_validate($data);
    if (!empty($error)) {
        return FALSE;
    }
    $book = new Book();
    $response = $book->create($data);
    if ($response['id'] > 0) {
        return book_list($response['id']);
    } else {
        return false;
    }
}
開發者ID:enettolima,項目名稱:mvno-platform,代碼行數:14,代碼來源:template_book.controller.php

示例13: test_book_nonnumber_quantity

 public function test_book_nonnumber_quantity()
 {
     // Validations are for 0.2 only  TODO Clean up this logic
     if ($this->version >= '0.2') {
         $data = array('title' => 'New Book', 'author_id' => '1', 'quantity' => 'string', 'price' => '7.77');
         $new_book = new Book();
         $new_book->create($data);
         // 'New Book' was created
         // e.g. create() isn't working
         if (!is_null($new_book->id)) {
             $this->errors['book_nonnumber_quantity'][] = 'created';
         }
     }
 }
開發者ID:TheOddLinguist,項目名稱:toolbox,代碼行數:14,代碼來源:tester.norm.validations.php

示例14: store

 public function store()
 {
     $validator = Validator::make($data = Input::all(), Book::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withPesan('Terdapat kesalahan validasi')->withInput();
     }
     $book = Book::create(Input::except('cover'));
     if (Input::hasFile('cover')) {
         $uploaded_cover = Input::file('cover');
         $extension = $uploaded_cover->getClientOriginalExtension();
         $filename = md5(time()) . '.' . $extension;
         $destination_path = public_path() . DIRECTORY_SEPARATOR . 'img';
         $uploaded_cover->move($destination_path, $filename);
         $book->cover = $filename;
         $book->save();
     }
     return Redirect::route('admin.books.index')->withPesan("Berhasil menyimpan {$book->title}");
 }
開發者ID:ryanda,項目名稱:larapus,代碼行數:18,代碼來源:BooksController.php

示例15: testDoubleSaveOneToMany

 public function testDoubleSaveOneToMany()
 {
     $author = User::create(array('name' => 'George R. R. Martin'));
     $book = Book::create(array('title' => 'A Game of Thrones'));
     $author->books()->save($book);
     $author->books()->save($book);
     $author->save();
     $this->assertEquals(1, $author->books()->count());
     $this->assertEquals($author->_id, $book->author_id);
     $author = User::where('name', 'George R. R. Martin')->first();
     $book = Book::where('title', 'A Game of Thrones')->first();
     $this->assertEquals(1, $author->books()->count());
     $this->assertEquals($author->_id, $book->author_id);
     $author->books()->save($book);
     $author->books()->save($book);
     $author->save();
     $this->assertEquals(1, $author->books()->count());
     $this->assertEquals($author->_id, $book->author_id);
 }
開發者ID:danielheyman,項目名稱:TechDimeProjects,代碼行數:19,代碼來源:RelationsTest.php


注:本文中的Book::create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。