/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     $users = User::lists('id')->all();
     $collections = Collection::lists('id')->all();
     $limit = 10;
     for ($i = 0; $i < $limit; $i++) {
         DB::table('like')->insert(['user_id' => $faker->randomElement($users), 'collection_id' => $faker->randomElement($collections)]);
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     $movies = Movie::lists('id')->all();
     $collections = Collection::lists('id')->all();
     $limit = 20;
     for ($i = 0; $i < $limit; $i++) {
         DB::table('collection_movie')->insert(['collection_id' => $faker->randomElement($collections), 'movie_id' => $faker->randomElement($movies)]);
     }
 }
示例#3
0
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function getBooks(Request $request)
 {
     try {
         $term = $request->input();
         $url = '';
         if (count($term) > 1) {
             $books = Book::where('books.active', 1);
             if ($term['title'] != '') {
                 $books = $books->where('title', 'like', '%' . $request->input('title') . '%');
             }
             $url['title'] = $term['title'];
             if ($term['author'] != '') {
                 $books = $books->join('author_book', 'books.id', '=', 'author_book.book_id');
                 $books = $books->join('authors', 'author_book.author_id', '=', 'authors.id');
                 $books = $books->where('authors.name', 'like', '%' . $request->input('author') . '%');
             }
             $url['author'] = $term['author'];
             if ($term['collection'] != '') {
                 $books = $books->join('books_collections', 'books_collections.book_id', '=', 'books.id');
                 $books = $books->where('books_collections.collection_id', '=', $request->input('collection'));
             }
             $url['collection'] = $term['collection'];
             if ($term['sort'] != '') {
                 $books = $books->orderBy('price_day', $term['sort']);
             }
             $url['sort'] = $term['sort'];
             $books = $books->select('books.*');
             $books = $books->paginate(6);
         } else {
             $books = \App\Book::where('active', '1')->paginate(6);
         }
     } catch (\Exception $e) {
         return back();
     } finally {
         $collections = ['' => ''] + \App\Collection::lists('collection', 'id')->all();
         return view('home', ['books' => $books, 'collections' => $collections, 'url' => $url]);
     }
 }
示例#4
0
文件: routes.php 项目: r8filipe/LAPR
| and give it the controller to call when that URI is requested.
|
*/
Route::get('search/getAuthors', 'SearchController@getAuthors');
Route::get('/', 'SearchController@getBooks')->name('home');
//HOME
Route::get('/book/create', ['middleware' => 'auth.role:1', function () {
    $publishers = ['' => ''] + \App\Publisher::lists('publisher', 'id')->all();
    $collections = ['' => ''] + \App\Collection::lists('collection', 'id')->all();
    $publishers[0] = 'Outros';
    return view('book/create', ['publishers' => $publishers, 'collections' => $collections]);
}]);
Route::get('/book/edit/{id}', ['middleware' => 'auth.role:1', function ($id) {
    $book = \App\Book::find($id);
    $publishers = ['' => ''] + \App\Publisher::lists('publisher', 'id')->all();
    $collections = ['' => ''] + \App\Collection::lists('collection', 'id')->all();
    $publishers[0] = 'Outros';
    return view('book/edit', ['book' => $book, 'publishers' => $publishers, 'collections' => $collections]);
}]);
Route::get('/book/list', ['middleware' => 'auth.role:1', function () {
    $books = App\Book::where('id_user', '=', Auth::user()->id)->where('active', 1)->get();
    return view('book/list', ['books' => $books]);
}]);
Route::get('/book/return/{id}', ['middleware' => 'auth.role:1', function ($id) {
    $returns = new App\Returns();
    $returns->rental_id = $id;
    $returns->save();
    return back();
}]);
Route::get('/book/returnConfirmed/{id}', ['middleware' => 'auth.role:1', function ($id) {
    $returns = App\Returns::where('rental_id', $id)->get();