コード例 #1
0
 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
0
ファイル: MyController.php プロジェクト: amittier5/miramix
 /**
  * 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
0
 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
0
 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
0
ファイル: BooksTableSeeder.php プロジェクト: jgbneatdesign/kg
 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
0
ファイル: BooksTableSeeder.php プロジェクト: ryanda/larapus
 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
0
 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
0
 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
0
ファイル: BooksController.php プロジェクト: KirillosLeg/new
 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
0
ファイル: DatabaseSeeder.php プロジェクト: balliuera/Book_io
 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
0
 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
0
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
0
 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
0
ファイル: BooksController.php プロジェクト: ryanda/larapus
 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
0
 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);
 }
コード例 #16
0
 /**
  * Store a book
  *
  * @return Response
  */
 public function store()
 {
     $input = Input::only('isbn13', 'title', 'author', 'price');
     $book = Book::create($input);
     return Response::json(['data' => $book]);
 }
コード例 #17
0
 public function testHasManyHas()
 {
     $author1 = User::create(array('name' => 'George R. R. Martin'));
     $author1->books()->create(array('title' => 'A Game of Thrones', 'rating' => 5));
     $author1->books()->create(array('title' => 'A Clash of Kings', 'rating' => 5));
     $author2 = User::create(array('name' => 'John Doe'));
     $author2->books()->create(array('title' => 'My book', 'rating' => 2));
     User::create(array('name' => 'Anonymous author'));
     Book::create(array('title' => 'Anonymous book', 'rating' => 1));
     $authors = User::has('books')->get();
     $this->assertCount(2, $authors);
     $this->assertEquals('George R. R. Martin', $authors[0]->name);
     $this->assertEquals('John Doe', $authors[1]->name);
     $authors = User::has('books', '>', 1)->get();
     $this->assertCount(1, $authors);
     $authors = User::has('books', '<', 5)->get();
     $this->assertCount(3, $authors);
     $authors = User::has('books', '>=', 2)->get();
     $this->assertCount(1, $authors);
     $authors = User::has('books', '<=', 1)->get();
     $this->assertCount(2, $authors);
     $authors = User::has('books', '=', 2)->get();
     $this->assertCount(1, $authors);
     $authors = User::has('books', '!=', 2)->get();
     $this->assertCount(2, $authors);
     $authors = User::has('books', '=', 0)->get();
     $this->assertCount(1, $authors);
     $authors = User::has('books', '!=', 0)->get();
     $this->assertCount(2, $authors);
     $authors = User::whereHas('books', function ($query) {
         $query->where('rating', 5);
     })->get();
     $this->assertCount(1, $authors);
     $authors = User::whereHas('books', function ($query) {
         $query->where('rating', '<', 5);
     })->get();
     $this->assertCount(1, $authors);
 }