本文整理汇总了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';
}
}
示例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');
}
示例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';
}
}
示例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]);
}
示例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));
}
示例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)]);
}
}
示例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'));
}
示例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');
}
示例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');
}
示例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()));
}
示例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);
}
示例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;
}
}
示例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';
}
}
}
示例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}");
}
示例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);
}