public function saveAuthor(Request $request) { if ($request->author_id != "") { $author = Author::find($request->author_id); $author->name = $request->name; $author->profile = $request->profile; $check = $author->save(); if ($check) { return "EDIT_SUCCEED"; } else { return "Có lỗi xảy ra. Vui lòng thử lại sau!"; } } else { $author = new Author(); $author->name = $request->name; $author->country = $request->country; $author->profile = $request->profile; $check = $author->save(); if ($check) { $data = array('msg' => 'ADD_SUCCEED', 'author_id' => $author->id); return $data; } else { return "Có lỗi xảy ra. Vui lòng thử lại sau!"; } } }
public function destroy(Author $author) { $deleted = $author->delete(); session()->flash('flash_message', 'Author was removed with success'); if (Request::wantsJson()) { return (string) $deleted; } return redirect('authors'); }
public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { Author::create(['name' => $faker->name]); } }
public static function editBook($data, $id) { $book = Book::find($id); if ($data['title'] != '') { $book->title = $data['title']; } if ($data['isbn10'] != '') { $book->isbn10 = $data['isbn10']; } $author = new Author(); $genre = new Genre(); $author->name = $data['author']; $genre->name = $data['genre']; $authorToRemove = Author::find($data['authors']); $genreToRemove = Genre::find($data['genres']); $exisitngAuthor = Author::find($data['existing-author']); $exisitngGenre = Genre::find($data['existing-genre']); $book->authors()->detach($authorToRemove['author_id']); $book->genres()->detach($genreToRemove['genre_id']); $book->authors()->attach($exisitngAuthor['author_id']); $book->genres()->attach($exisitngGenre['genre_id']); if ($data['author'] != '') { $book->authors()->save($author); var_dump($data['author']); } if ($data['genre'] != '') { $book->genres()->save($genre); } $book->save(); }
public function index() { $books = Book::with('Author')->where(function ($query) { $min_price = \Request::has('min_price') ? \Request::get('min_price') : null; $max_price = \Request::has('max_price') ? \Request::get('max_price') : null; $authors = \Request::has('authors') ? \Request::get('authors') : []; if (isset($min_price)) { $query->where('price', '>=', $min_price); } if (isset($max_price)) { $query->where('price', '<=', $max_price); } if (isset($authors)) { $query->where(function ($q) { $input_authors = \Request::has('authors') ? \Request::get('authors') : []; // $books_all = \App\Book::with('Author')->get(); //перебираем все чекнутые боксы foreach ($input_authors as $input_author) { // автор == выборка из авторов где Ид = чекнутому боксу. Первый $author = \App\Author::with('books')->where('id', '=', $input_author)->first(); // выборка внутри выбранного автора по книгам foreach ($author->books as $author_book) { //запрос Айди книги == айди книг у этого автора $q->orWhere('id', '=', $author_book->id); } } }); } })->paginate(2); $authors_list = \App\Author::all(); return view('books.list', compact('books', 'authors_list')); }
/** * Show the form for editing the specified resource. * * @param Quote $quote * * @return Response * @internal param int $id */ public function edit(Quote $quote) { $authors = Author::lists('name', 'id')->all(); $categories = Category::lists('name', 'id')->all(); $categoriesOfImages = ImageCategory::lists('name', 'id')->all(); return view('admin.quote.edit', compact('quote'))->withTitle('Edit: ' . $quote->title)->withAuthors($authors)->withCategories($categories)->with('categoriesOfImages', $categoriesOfImages); }
public function editAuthor($request, $response, $params) { $author = Author::find((int) $params['author_id']); if (!$author) { $uri = $request->getUri()->withQuery('')->withPath($this->router->pathFor('list-authors')); return $response->withRedirect((string) $uri); } $errors = null; if ($request->isPost()) { if ($request->getAttribute('csrf_status') === false) { $errors['form'] = 'CSRF failure'; } else { $data = $request->getParsedBody(); $validator = $author->getValidator($data); if ($validator->validate()) { $author->update($data); $this->flash->addMessage('message', 'Author updated'); $uri = $request->getUri()->withQuery('')->withPath($this->router->pathFor('author', ['author_id' => $author->id])); return $response->withRedirect((string) $uri); } else { $errors = $validator->errors(); } } } return $this->view->render($response, 'author/edit.twig', ['author' => $author, 'errors' => $errors, 'csrf' => ['name' => $request->getAttribute('csrf_name'), 'value' => $request->getAttribute('csrf_value')]]); }
/** * Show the application welcome screen to the user. * * @return Response */ public function index() { $events = Event::take('4')->get(); $authors = Author::take('4')->get(); $coverage = DB::table('press')->take('4')->orderBy('press_date', 'desc')->get(); return view('welcome', compact('events', 'authors', 'coverage')); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $book = Book::find($id); $authors = Author::lists('name', 'author_id'); $genres = Genre::lists('name', 'genre_id'); return view('books/book-edit', ['id' => $id, 'authors' => $authors, 'genres' => $genres]); }
/** * Run the database seeds. * * @return void */ public function run() { DatabaseSeeder::truncateTable('phones'); $authors = \App\Author::all(); foreach ($authors as $author) { \App\Phone::create(['author_id' => $author->id, 'phone_number' => '0' . (string) (9099990000 + $author->id)]); } }
public function getAuthorsForDropdown() { $authors = \App\Author::orderby('last_name', 'ASC')->get(); $authors_for_dropdown = []; foreach ($authors as $author) { $authors_for_dropdown[$author->id] = $author->last_name . ', ' . $author->first_name; } return $authors_for_dropdown; }
public function getAuthors(Request $request) { $term = $request->input('term'); $authors = Author::where('name', 'like', '%' . $term . '%')->get(); foreach ($authors as $author) { $aut[] = $author->name; } return json_encode($aut); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $application = Application::find($id); $author = Author::find($id); $applications = Application::all(); $authors = Author::all(); $versions = [1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0]; return view('application.edit', compact('application', 'author', 'applications', 'authors', 'versions')); }
/** * Run the database seeds. * * @return void */ public function run() { $author_id = \App\Author::where('last_name', '=', 'Fitzgerald')->pluck('id'); DB::table('books')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'title' => 'The Great Gatsby', 'author_id' => $author_id, 'user_id' => 1, 'published' => 1925, 'cover' => 'http://img2.imagesbn.com/p/9780743273565_p0_v4_s114x166.JPG', 'purchase_link' => 'http://www.barnesandnoble.com/w/the-great-gatsby-francis-scott-fitzgerald/1116668135?ean=9780743273565']); $author_id = \App\Author::where('last_name', '=', 'Plath')->pluck('id'); DB::table('books')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'title' => 'The Bell Jar', 'author_id' => $author_id, 'user_id' => 1, 'published' => 1963, 'cover' => 'http://img1.imagesbn.com/p/9780061148514_p0_v2_s114x166.JPG', 'purchase_link' => 'http://www.barnesandnoble.com/w/bell-jar-sylvia-plath/1100550703?ean=9780061148514']); $author_id = \App\Author::where('last_name', '=', 'Angelou')->pluck('id'); DB::table('books')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'title' => 'I Know Why the Caged Bird Sings', 'author_id' => $author_id, 'user_id' => 1, 'published' => 1969, 'cover' => 'http://img1.imagesbn.com/p/9780345514400_p0_v1_s114x166.JPG', 'purchase_link' => 'http://www.barnesandnoble.com/w/i-know-why-the-caged-bird-sings-maya-angelou/1100392955?ean=9780345514400']); }
/** * Run the database seeds. * * @return void */ public function run() { //clean up tables DB::table('authors')->delete(); // create Authors Author::create(["name" => "Aleksander", "surname" => "Pushkin"]); Author::create(["name" => "Sergei", "surname" => "Esenin"]); Author::create(["name" => "Dan", "surname" => "Brown"]); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); DB::table('authors')->delete(); $faker = Faker::create(); for ($i = 0; $i < 10; $i++) { Author::create(['email' => $faker->companyEmail, 'company_name' => $faker->company]); } Model::reguard(); }
/** * 检查作者是否存在 * **/ public function isAuthorExist($payload) { if ($payload['feed']) { $author = Author::where('feed', $payload['feed'])->first(); if ($author) { return true; } else { return false; } } }
/** * Run the database seeds. * * @return void */ public function run() { $author_id = \App\Author::where('last_name', '=', 'Fitzgerald')->pluck('id'); DB::table('books')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'title' => '1.mp4', 'author_id' => $author_id, 'user_id' => 1, 'published' => 100, 'cover' => 'img/thumbnail.png', 'purchase_link' => 'this video gives a overview of the .etc file']); $author_id = \App\Author::where('last_name', '=', 'Plath')->pluck('id'); DB::table('books')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'title' => '2.mp4', 'author_id' => $author_id, 'user_id' => 1, 'published' => 90, 'cover' => 'img/thumbnail.png', 'purchase_link' => 'this is a high level view of the way Laravel is a framework of frameworks']); $author_id = \App\Author::where('last_name', '=', 'Angelou')->pluck('id'); DB::table('books')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'title' => '3.mp4', 'author_id' => $author_id, 'user_id' => 1, 'published' => 90, 'cover' => 'img/thumbnail.png', 'purchase_link' => 'this describes the way Laravel uses the MVC framework']); $author_id = \App\Author::where('last_name', '=', 'Angelou')->pluck('id'); DB::table('books')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'title' => '4.mp4', 'author_id' => $author_id, 'user_id' => 1, 'published' => 90, 'cover' => 'img/thumbnail.png', 'purchase_link' => 'this discusses the routes.php file']); }
public function syncAuthors($authors) { Author::addNeededAuthors($authors); $authors = explode(',', $authors); if (count($authors)) { $authors = Author::whereIn('name', $authors)->lists('id')->all(); $this->authors()->sync($authors); return; } $this->author()->detach(); }
/** * Display the quotes for given author. * * @param $slug * * @return Response * @internal param int $slug */ public function quotes($slug) { try { $author = Author::where(['slug' => $slug])->firstOrFail(); $statusCode = 200; $response = ['data' => $author->quotes()->get()]; } catch (Exception $e) { $statusCode = 400; } finally { return Response::json($response, $statusCode); } }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); DB::table('applications')->delete(); $authors = Author::all(); $faker = Faker::create(); foreach ($authors as $author) { for ($i = 0; $i < 1; $i++) { Application::create(['title' => $faker->company, 'version' => $faker->randomFloat($nbMaxDecimals = 1, $min = 1, $max = 3), 'author_id' => $author->id]); } } Model::reguard(); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { $data = Request::all(); $rules = ['authorcode' => 'required|numeric', 'authorfname' => 'required|alpha', 'authorlname' => 'required|alpha', 'authormname' => 'alpha']; $message = ['authorcode.required' => 'Author Code should not be empty.', 'authorcode.numeric' => 'Author Code may contain numbers only.', 'authorfname.required' => 'First Name should not be empty.', 'authorfname.alpha' => 'First Name may contain letters only.', 'authorlname.required' => 'Last Name should not be empty.', 'authorlname.alpha' => 'Last Name may contain letters only.', 'authormname.alpha' => 'Middle initial may contain letters only.']; $validation = Validator::make($data, $rules, $message); if ($validation->passes()) { if (Author::find($data['authorcode'])) { return back()->withInput(); } else { $author = new Author(); $author->authorcode = $data['authorcode']; $author->authorfname = $data['authorfname']; $author->authormname = $data['authormname']; $author->authorlname = $data['authorlname']; $author->authororder = $data['authororder']; $author->authortitle = $data['authortitle']; $author->save(); return Redirect::to('/index'); } } else { return Redirect::back()->withInput()->withErrors($validation); } }
/** * Responds to requests to GET /books/edit/{$id} */ public function getEdit($id = null) { $book = \App\Book::find($id); $authors = \App\Author::orderby('last_name', 'ASC')->get(); $authors_for_dropdown = []; foreach ($authors as $author) { $authors_for_dropdown[$author->id] = $author->last_name . ', ' . $author->first_name; } #dump($authors_for_dropdown); if (is_null($book)) { \Session::flash('flash_message', 'Book not found.'); return redirect('\\books'); } return view('books.edit')->with(['book' => $book, 'authors_for_dropdown' => $authors_for_dropdown]); }
/** * Run the database seeds. * * @return void */ public function run() { DatabaseSeeder::truncateTable('author_author_type'); DatabaseSeeder::truncateTable('author_types'); try { factory(\App\AuthorType::class, 10)->create(); } catch (\Illuminate\Database\QueryException $e) { // name カラムの unique index の無視 } $authors = \App\Author::all(); /** @var \App\Author $author */ foreach ($authors as $author) { $author_types = \App\AuthorType::all()->random(rand(2, 5)); $author->types()->sync($author_types); } }
public function __construct() { $A_authors = Author::all(); view()->share('A_authors', $A_authors); $A_projects = Project::all(); view()->share('A_projects', $A_projects); $A_blogs = Blog::all(); view()->share('A_blogs', $A_blogs); $A_newsletters = Newsletter::all(); view()->share('A_newsletters', $A_newsletters); $A_quotations = Quotation::all(); view()->share('A_quotations', $A_quotations); $quotations = Quotation::all(); //dump($quotations); $quotations = count($quotations) > 1 ? $quotations->random(2) : $quotations; view()->share('quotations', $quotations); }
public function saveBook(Request $request) { if ($request->book_id != "") { $book = Book::find($request->book_id); $book->title = $request->title; $book->genre_id = $request->genre_id; $book->author_id = $request->author_id; $book->publisher_id = $request->publisher_id; $book->image = $request->image; $book->isbn = $request->isbn; $book->description_short = $request->description_short; $book->description = $request->description; $book->price = $request->price; $book->sale = $request->sale; $book->quantity = $request->quantity; $check = $book->save(); if ($check) { return "EDIT_SUCCEED"; } else { return "Có lỗi xảy ra. Vui lòng thử lại sau!"; } } else { $book = new Book(); $book->title = $request->title; $book->genre_id = $request->genre_id; $book->author_id = $request->author_id; $book->publisher_id = $request->publisher_id; $book->image = $request->image; $book->isbn = $request->isbn; $book->description_short = $request->description_short; $book->description = $request->description; $book->price = $request->price; $book->sale = $request->sale; $book->quantity = $request->quantity; $check = $book->save(); if ($check) { $genre_name = Genre::find($request->genre_id)->name; $author_name = Author::find($request->author_id)->name; $data = array('msg' => 'ADD_SUCCEED', 'book_id' => $book->id, 'genre_name' => $genre_name, 'author_name' => $author_name); return $data; } else { return "Có lỗi xảy ra. Vui lòng thử lại sau!"; } } }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { $author = \App\Author::find($id); if ($author) { $rules = \App\Author::$rules; //$rules['name'] = 'required|min:2'; $validator = \Validator::make(\Input::all(), $rules); if ($validator->passes()) { $author = \App\Author::find($id); $author->name = \Input::get('name'); $author->save(); flash('Author updated.'); return \Redirect::back(); } return \Redirect::back()->withInput()->withErrors($validator); } flash()->error('Author does not exist.'); return \Redirect::back(); }
/** * Run the database seeds. * * @return void */ public function run() { // (1) データを一旦削除する DatabaseSeeder::truncateTable('authors'); // (2) DBファサードを利用したデータの挿入 $authors = []; $now = \Carbon\Carbon::now(); for ($i = 1; $i <= 10; $i++) { $authors[] = ['name' => '著者名' . $i, 'furigana' => 'フリガナ' . $i, 'romaji' => 'Romaji' . $i]; } foreach ($authors as $author) { $author['created_at'] = $now; $author['updated_at'] = $now; DB::table('authors')->insert($author); } // (3) Eloquentを利用したデータの挿入 for ($i = 11; $i <= 20; $i++) { \App\Author::create(['name' => '著者名' . $i, 'furigana' => 'フリガナ' . $i, 'romaji' => 'Romaji' . $i]); } }
public function addbooks() { header('Content-Type: text/html; charset=utf-8'); for ($i = 0; $i <= 10; $i++) { $user = new User(); $user->name = $this->generateRandomString(5); $user->password = bcrypt($user->name); $user->email = $user->name . '@gmail.com'; $user->save(); } $names = ['%22feliz%20gouveia%22', '%22nuno%20ribeiro%22', '%22jose%20torres%22', '%22borges%20gouveia%22', '%22Sophia%20breyner%22', '%22Fernando%20Pessoa%22', '%22Eça%20De%20Queiros%22']; foreach ($names as $name) { $content = file_get_contents('https://www.googleapis.com/books/v1/volumes?q=' . $name); $content = json_decode($content, true); $auts = Author::all('name'); $authors = array(); foreach ($auts as $aut) { $authors[] = $aut['name']; } $pubs = Publisher::all('publisher'); $publishers = array(); foreach ($pubs as $pub) { $publishers[] = $pub['publisher']; } $cats = Collection::all('collection'); $categories = array(); foreach ($cats as $cat) { $categories[] = $cat['collection']; } foreach ($content['items'] as $data) { $data = $data['volumeInfo']; $book = new Book(); if (isset($data['title'])) { $book->title = $data['title']; } if (isset($data['subtitle'])) { $book->subtitle = $data['subtitle']; } if (isset($data['publishedDate'])) { $book->publishedDate = $data['publishedDate']; } if (isset($data['description'])) { $book->description = $data['description']; } if (isset($data['pageCount'])) { $book->pages = $data['pageCount']; } if (isset($data['language'])) { $book->language = $data['language']; } if (isset($data['industryIdentifiers'])) { foreach ($data['industryIdentifiers'] as $value) { if ($value['type'] == 'ISBN_13') { $book->isbn13 = $value['identifier']; } if ($value['type'] == 'ISBN_10') { $book->isbn10 = $value['identifier']; } } } if (isset($data['publisher'])) { if (!in_array($data['publisher'], $publishers)) { $publishers[] = $data['publisher']; $publisher = new Publisher(); $publisher->publisher = $data['publisher']; $publisher->save(); $publisher_id = $publisher->id; } else { $publisher = Publisher::where('publisher', '=', $data['publisher'])->limit(1)->get(); $publisher_id = $publisher[0]->id; } } if (isset($data['imageLinks']['thumbnail'])) { $book->cover = file_get_contents($data['imageLinks']['thumbnail']); } $book->price_day = random_int(0, 15); $book->price_bail = random_int(10, 50); $book->price_sale = random_int(10, 79); $books[] = $book; $book->id_publisher = $publisher_id; $book->id_user = rand(1, 10); $book->save(); $book_id = $book->id; if (isset($data['categories'])) { foreach ($data['categories'] as $value) { if (!in_array($value, $categories)) { $categories[] = $value; $category = new Collection(); $category->collection = $value; $category->save(); $category_id = $category->id; $collections = new Book_Collection(); $collections->book_id = $book_id; $collections->collection_id = $category_id; $collections->save(); } else { $category = Collection::where('collection', '=', $value)->limit(1)->get(); $collections = new Book_Collection(); $collections->book_id = $book_id; $collections->collection_id = $category[0]->id; $collections->save(); } } } if (isset($data['authors'])) { foreach ($data['authors'] as $value) { if (!in_array($value, $authors)) { $authors[] = $value; $author = new Author(); $author->name = $value; $author->save(); $author_id = $author->id; $author_book = new Author_Book(); $author_book->book_id = $book_id; $author_book->author_id = $author_id; $author_book->save(); } else { $author = Author::where('name', 'like', $value)->limit(1)->get(); $author_book = new Author_Book(); $author_book->book_id = $book_id; $author_book->author_id = $author[0]->id; $author_book->save(); } } } # code... } } }
public function allNames() { return Author::lists('name', 'id')->all(); }