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'));
 }
 /**
  * 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 index()
 {
     $authors = Author::all();
     if (Request::wantsJson()) {
         return $authors;
     }
     return view('authors.index', compact('authors'));
 }
 /**
  * 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'));
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     try {
         $quotes = Author::all();
         $statusCode = 200;
         $response = ['data' => $quotes];
     } 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();
 }
 /**
  * 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);
     }
 }
示例#8
0
 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);
 }
示例#9
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $authors = \App\Author::all();
     return view('authors.index', ['authors' => $authors]);
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $authors = Author::all();
     return $this->respondTo(['html' => view('authors.index', compact('authors')), 'default' => $authors]);
 }
示例#11
0
 public function listAuthors($request, $response)
 {
     return $this->view->render($response, 'author/list.twig', ['authors' => Author::all()]);
 }
示例#12
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $book = \App\Book::with('authors', 'publisher', 'category', 'language')->findOrFail($id);
     $authors = \App\Author::all()->lists('name', 'name');
     $book_authors = $book->authors()->lists('name');
     // return $book_authors;
     return view('books.edit')->with(compact('book'))->with(compact('authors', 'book_authors'));
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function getIndex()
 {
     //
     $users = Author::all();
     return view('authors.index', compact('users'));
 }
 public function index()
 {
     $authors = \App\Author::all();
     return view('author.index', compact('authors'));
 }
 public function index()
 {
     $authors = Author::all();
     return json_encode($authors);
 }
示例#16
0
 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...
         }
     }
 }
示例#17
0
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function create()
 {
     $applications = Application::all();
     $authors = Author::all();
     return view('application.create', compact('applications', 'authors'));
 }
 public function create()
 {
     $authors = \App\Author::all();
     $category = \App\Category::all();
     return view('admin.create', compact('authors', 'category'));
 }
 public function getAuthors()
 {
     $authors = Author::all();
     return view('admin.authors', compact('authors'));
 }
示例#20
0
 public function showQuotation($id)
 {
     $quotation = Quotation::findOrFail($id);
     $authors = Author::all();
     return view('administration.quotation.showQuotation')->with('quotation', $quotation)->with('authors', $authors);
 }
示例#21
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $authors = Author::all();
     return view('authors/authors', ['authors' => $authors]);
 }