本文整理汇总了PHP中app\Book::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::create方法的具体用法?PHP Book::create怎么用?PHP Book::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Book
的用法示例。
在下文中一共展示了Book::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('books')->delete();
Book::create(['title' => 'Eugenii Onegin', 'isbn' => '09374726342', 'price' => '10.40', 'cover' => 'onegin.jpg', 'author_id' => '1']);
Book::create(['title' => 'Stihi', 'isbn' => '5555555555', 'price' => '8.25', 'cover' => 'esenin_stihi.jpg', 'author_id' => '2']);
Book::create(['title' => 'Angels and demons', 'isbn' => '1111111111', 'price' => '15.99', 'cover' => 'brown_angels.jpg', 'author_id' => '3']);
}
示例2: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
//
$book = Request::all();
Book::create($book);
return redirect('books');
}
示例3: run
public function run()
{
DB::table('books')->delete();
Book::create(['title' => 'A Tale of Two Cities', 'author' => 'Charles Dickens', 'year' => '1859']);
Book::create(['title' => 'The Lord of the Rings', 'author' => 'J. R. R. Tolkien', 'year' => '1954']);
Book::create(['title' => 'And Then There Were None', 'author' => 'Agatha Christie', 'year' => '1939']);
Book::create(['title' => 'The Hobbit', 'author' => 'J. R. R. Tolkien', 'year' => '1937']);
Book::create(['title' => 'She: A History of Adventure', 'author' => 'H. Rider Haggard', 'year' => '1887']);
Book::create(['title' => 'The Lion the Witch and the Wardrobe', 'author' => 'C. S. Lewis', 'year' => '1950']);
Book::create(['title' => 'The Da Vinci Code', 'author' => 'Dan Brown', 'year' => '2003']);
Book::create(['title' => 'The Catcher in the Rye', 'author' => 'J. D. Salinger', 'year' => '1951']);
Book::create(['title' => 'Lolita', 'author' => 'Vladimir Nabokov', 'year' => '1955']);
Book::create(['title' => 'Anne of Green Gables', 'author' => 'Lucy Maud Montgomery', 'year' => '1908']);
Book::create(['title' => 'The Name of the Rose', 'author' => 'Umberto Eco', 'year' => '1980']);
Book::create(['title' => 'The Eagle Has Landed', 'author' => 'Jack Higgins', 'year' => '1975']);
Book::create(['title' => 'Watership Down', 'author' => 'Richard Adams', 'year' => '1972 ']);
Book::create(['title' => 'The Ginger Man', 'author' => 'J. P. Donleavy', 'year' => '1955']);
Book::create(['title' => 'The Bridges of Madison County', 'author' => 'Robert James Waller', 'year' => '1991']);
Book::create(['title' => 'The Tale of Peter Rabbit', 'author' => 'Beatrix Potter', 'year' => '1902']);
Book::create(['title' => 'Harry Potter and the Deathly Hallows', 'author' => 'J. K. Rowling', 'year' => '2007']);
Book::create(['title' => 'Jonathan Livingston Seagull', 'author' => 'Richard Bach', 'year' => '1970']);
Book::create(['title' => 'A Message to Garcia', 'author' => 'Elbert Hubbard', 'year' => '1899']);
Book::create(['title' => 'Flowers in the Attic', 'author' => 'V. C. Andrews', 'year' => '1979']);
Book::create(['title' => 'War and Peace', 'author' => 'Leo Tolstoy', 'year' => '1869']);
Book::create(['title' => 'The Adventures of Pinocchio', 'author' => 'Carlo Collodi', 'year' => '1881']);
Book::create(['title' => 'Kane and Abel', 'author' => 'Jeffrey Archer', 'year' => '1979']);
Book::create(['title' => 'To Kill a Mockingbird', 'author' => 'Harper Lee', 'year' => '1960']);
Book::create(['title' => 'Valley of the Dolls', 'author' => 'Jacqueline Susann', 'year' => '1966']);
Book::create(['title' => 'Gone with the Wind', 'author' => 'Margaret Mitchell', 'year' => '1936']);
Book::create(['title' => 'The Diary of a Young Girl', 'author' => 'Anne Frank', 'year' => '1947']);
Book::create(['title' => 'One Hundred Years of Solitude', 'author' => 'Gabriel Garcia Marquez', 'year' => '1967']);
Book::create(['title' => 'The Thorn Birds', 'author' => 'Colleen McCullough', 'year' => '1977']);
Book::create(['title' => 'The Revolt of Mamie Stover', 'author' => 'William Bradford Huie', 'year' => '1951']);
Book::create(['title' => 'The Girl with the Dragon Tattoo', 'author' => 'Stieg Larsson', 'year' => '2005']);
}
示例4: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(CreateBookRequest $request)
{
$user = \Auth::User();
if (!$user) {
return view('auth.login')->withErrors('You are not loged in, please loged in !');
}
$book = $request->bookFillData();
$book['user_id'] = $user->id;
$book['published_at'] = Carbon::parse($request->get('published_at'))->format('Y-m-d');
$fileSizeValidation = \Config::get('library.image_file_size');
$newBook = Book::create($book);
$newBook->syncAuthors($request->get('authors'));
$this->manager->createDirectory($newBook->id);
$file = $_FILES['image'];
if ($file['size'] > 0) {
// Additional image validation
if (!starts_with($file['type'], 'image/')) {
return Redirect::action('BookController@create')->withErrors('Invalid file format, please use image !');
}
$fileSize = $file['size'] / 1024;
if ($fileSize > $fileSizeValidation) {
return Redirect::action('BookController@create')->withErrors('The image may not be greater than ' . $fileSizeValidation . ' kilobytes. ');
}
$img = Image::make($_FILES['image']['tmp_name']);
$img->resize(140, 140);
$img->save('.' . \Config::get('library.uploads.webpath') . DIRECTORY_SEPARATOR . $newBook->id . '/cover.jpg');
}
return redirect::action('BookController@index')->withSuccess("The book with title '{$newBook->title}' was created.");
}
示例5: 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, ['isbn' => 'required', 'title' => 'required', 'author' => 'required', 'publisher' => 'required', 'language' => 'required']);
$input = $request->all();
Book::create($input);
Session::flash('flash_message', 'Book successfully added!');
return redirect()->back();
}
示例6: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Requests\BooksRequest $r)
{
$book = $r->all();
$book['addedDate'] = Carbon::now();
$book['userAdd'] = Auth::user()->id;
Book::create($book);
return redirect('/home');
}
示例7: store
public function store(Requests\User $request)
{
$all = $request->all();
\App\Book::create($all);
echo '<pre>';
print_r($all);
die;
return redirect('books');
}
示例8: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Requests\CreateBookRequest $request)
{
$input = $request->all();
if (\App\Book::create($input)) {
return response()->json(['msg' => 'success'], 201);
} else {
return response()->json(['msg' => 'error', 'error' => 'cannot create record'], 400);
}
}
示例9: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('lends')->delete();
DB::table('users')->delete();
User::create(['id' => '1', 'name' => '郑文凯', 'email' => '123@qq.com', 'password' => Hash::make('123'), 'is_admin' => 1, 'reserve_num' => 1]);
User::create(['id' => '2', 'name' => '陈翔宇', 'email' => '1@qq.com', 'password' => Hash::make('1'), 'is_admin' => 0, 'reserve_num' => 10]);
DB::table('books')->delete();
Book::create(['id' => '1', 'book_name' => '书名', 'author' => '作者', 'ISBN' => '123456', 'press_name' => '出版社', 'press_date' => '123456', 'url' => '链接', 'in_use' => '0']);
Lend::create(['user_id' => '2', 'book_id' => '1', 'lend_date' => '1234', 'due_date' => '2345', 'return_date' => '3456', 'continued' => '1', 'is_returned' => '0']);
}
示例10: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('books')->insert(['name' => 'test book1', 'type' => 'islamic', 'description' => 'good book', 'published_at' => Carbon\Carbon::now(), 'price' => 1000.0, 'pages' => 343, 'author' => 'Amina Nisar', 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')]);
Book::create(['name' => 'zoo2', 'type' => 'general', 'description' => 'good book', 'published_at' => Carbon\Carbon::now(), 'price' => 10444.0, 'pages' => 3463, 'author' => 'Amina Nisar']);
Book::create(['name' => 'history3', 'type' => 'general', 'description' => 'good book', 'published_at' => Carbon\Carbon::now(), 'price' => 10444.0, 'pages' => 3463, 'author' => 'Amina Nisar']);
Book::create(['name' => 'hello world4', 'type' => 'general', 'description' => 'good book', 'published_at' => Carbon\Carbon::now(), 'price' => 10444.0, 'pages' => 3463, 'author' => 'Amina Nisar']);
Book::create(['name' => 'Databases5', 'type' => 'general', 'description' => 'good book', 'published_at' => Carbon\Carbon::now(), 'price' => 10444.0, 'pages' => 3463, 'author' => 'Amina Nisar']);
Book::create(['name' => 'seeders6', 'type' => 'general', 'description' => 'good book', 'published_at' => Carbon\Carbon::now(), 'price' => 10444.0, 'pages' => 3463, 'author' => 'Amina Nisar']);
Book::create(['name' => 'helper7', 'type' => 'general', 'description' => 'good book', 'published_at' => Carbon\Carbon::now(), 'price' => 10444.0, 'pages' => 3463, 'author' => 'Amina Nisar']);
Book::create(['name' => 'future8', 'type' => 'general', 'description' => 'good book', 'published_at' => Carbon\Carbon::now(), 'price' => 10444.0, 'pages' => 3463, 'author' => 'Amina Nisar']);
Book::create(['name' => 'programming9', 'type' => 'general', 'description' => 'good book', 'published_at' => Carbon\Carbon::now(), 'price' => 10444.0, 'pages' => 3463, 'author' => 'Amina Nisar']);
}
示例11: postStore
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function postStore(Request $request)
{
//usando request
$data = $request->all();
//usando metodo create (obs: é necessario ter o metodo filabo)
/*$data = ['title' => 'Game of Thrones', 'description' => 'Livro massa pra caramba'];*/
Book::create($data);
//usando o save
/*$book->title = 'Alto da barca do Céu';
$book->description = 'Descrição de livro';
$book->save();*/
return redirect('books');
}
示例12: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$input = $request->all();
//dd($input);
if (isset($input['filepath'])) {
$imgPath = $this->imageUpload($input['filepath']);
$input['filepath'] = $imgPath;
} else {
$input['filepath'] = "modules/image.jpeg";
}
Book::create($input);
return redirect('BARD_book')->with('status', 'Create successfully');
}
示例13: save
/**
* @param StoreBookPostRequest $request
* @return mixed
*/
public function save(StoreBookPostRequest $request)
{
$bookId = Input::get('book_id');
if ($bookId) {
$book = Book::find($bookId);
$book->update(Input::all());
} else {
$book = Book::create(Input::all());
$this->notifyUsers($book);
}
if (!$book) {
return Redirect::back()->with('message', 'Something wrong happened while saving your model')->withInput();
}
return Redirect::route('books')->with('message', sprintf('Book "%s" saved', $book->title));
}
示例14: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$book = Request::all();
$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
// $this->create_thumbnail($thumb_path,$fileName,$extension);
$book['image'] = $fileName;
Book::create($book);
Session::flash('success', 'Upload successfully');
return redirect('admin/book');
}
示例15: store
public function store()
{
if (\Request::file('cover')->isValid()) {
$file = \Request::file('cover');
$destinationPath = './images';
//public_path() .
$extension = \Request::file('cover')->getClientOriginalExtension();
$filename = rand(1111111, 9999999) . '.' . $extension;
$file->move($destinationPath, $filename);
$image = \App\Image::create(['path' => './images/' . $filename, 'description' => 'main']);
} else {
return redirect()->back()->withInput()->with('message', 'image file invalid');
}
$book = \App\Book::create(['title' => \Request::get('title'), 'isbn' => \Request::get('isbn'), 'price' => \Request::get('price'), 'cover' => $filename]);
$book->images()->attach($image->id);
$book->Author()->attach(\Request::get('author_id'));
$book->categories()->attach(\Request::get('category'));
return redirect('./admin/products')->with('message', 'product created');
}