本文整理汇总了PHP中app\Book::all方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::all方法的具体用法?PHP Book::all怎么用?PHP Book::all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Book
的用法示例。
在下文中一共展示了Book::all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$user = Auth::user();
$books = Book::all();
$transactions = User::order()->get();
return view('operator.order.index', ['user' => $user, 'books' => $books, 'transactions' => $transactions]);
}
示例2: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$user = Auth::user();
$books = Book::all();
$transactions = User::join('book_users', 'users.id', '=', 'book_users.user_id')->join('books', 'books.id', '=', 'book_users.book_id')->select('books.title', 'users.name', 'book_users.created_at', 'book_users.updated_at', 'book_users.status')->whereNotIn('status', ['pesan'])->get();
return view('operator.borrow.index', ['user' => $user, 'books' => $books, 'transactions' => $transactions]);
}
示例3: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
//
$books = Book::all();
return view('books.index', compact('books'));
//return view('welcome');
}
示例4: index
public function index()
{
//$book = new \App\Book();
//$books = $book->all();
$books = \App\Book::all();
return view('books', ['books' => $books]);
}
示例5: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$user = Auth::user();
$books = Book::all();
$transactions = User::transactionBorrow()->orderBy('created_at', 'desc')->get();
return view('operator.transactions.index', ['user' => $user, 'books' => $books, 'transactions' => $transactions]);
}
示例6: getBookWithEloquent
function getBookWithEloquent()
{
$books = new Book();
foreach ($books->all() as $book) {
echo $book->title . '<br/>';
}
return 'getBookWithEloquent';
}
示例7: foreach
function getExample9()
{
#eager load the authors with the books
$books = \App\Book::all();
foreach ($books as $book) {
echo $book->author->first_name . ' ' . $book->author->last_name . ' wrote ';
}
dump($books->toArray());
}
示例8: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// Add to 10 random user 5 random books
$users = User::all('id')->random(5);
foreach ($users as $user) {
$books = Book::all('id')->random(3);
foreach ($books as $book) {
DB::table('users_books')->insert(['user_id' => $user->id, 'book_id' => $book->id]);
}
}
}
示例9: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$books = Book::all();
foreach ($books as $book) {
//TODO: make a method in model for retreiving authors and genres
$authors = Book::find($book->book_id)->authors()->get();
$genres = Book::find($book->book_id)->genres()->get();
$book->authors = $authors;
$book->genres = $genres;
}
return view('books/books', ['books' => $books]);
}
示例10: index
public function index()
{
$books = \App\Book::all();
$category = \App\Category::all();
// return \App\Book::with(["Author"])->get();
// dd($books->toArray());
// if (!\Auth::user()->admin == '1')
// {
// return \Redirect::to('index')->with('error', 'You are not Admin');
// }
return view('admin.bookslist', compact('books', 'category'));
}
示例11: index
/**
* Displays a listing of all the books available and allows their sorting as well.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$sortBy = Input::get('sortBy');
$order = Input::get('order');
if ($sortBy and $order == 'asc') {
$books = Book::orderBy($sortBy, 'ASC')->get();
} elseif ($sortBy and $order == "desc") {
$books = Book::orderBy($sortBy, 'DESC')->get();
} else {
$books = Book::all();
}
return view('home')->with('books', $books);
}
示例12: showBooks
public function showBooks()
{
$books = Book::all();
function getExcerpt($str, $startPos = 0, $maxLength = 100)
{
if (strlen($str) > $maxLength) {
$excerpt = substr($str, $startPos, $maxLength - 3);
$lastSpace = strrpos($excerpt, ' ');
$excerpt = substr($excerpt, 0, $lastSpace);
$excerpt .= ' ...';
} else {
$excerpt = $str;
}
return $excerpt;
}
foreach ($books as $book) {
$book->description = getExcerpt($book->description, 0, 1000);
}
return View('books', compact('books'));
}
示例13: importBooks
public function importBooks()
{
$rules = array('csvfile' => 'required|mimes:csv,txt');
try {
$file = Input::file('csvfile');
if (is_null($file)) {
throw new Exception("File upload required");
}
Excel::load($file, function ($reader) {
$results = $reader->all();
foreach ($results as $row) {
$book = new Book();
# First row should be like "Title, Author"
$data = array('title' => $row->title, 'author' => $row->author);
$book->fill($data);
$book->save();
}
});
} catch (Exception $e) {
return Redirect::to('/')->with(['books' => Book::all(), 'errors' => $e->getMessage()]);
}
return Redirect::to('/')->with(['books' => Book::all()]);
//return Redirect::to('/')->with('csvdata', $results);
}
示例14: getNearestUser
public function getNearestUser(Request $request, $book_id)
{
session_start();
if (session_id() == "" || !isset($_SESSION['latitude'])) {
return redirect()->route('home');
} else {
if (isset($_SESSION['latitude'])) {
// get all the books from the book database.
$books = Book::where("book_id", $book_id)->get();
$valid_users = [];
foreach ($books as $book) {
$matches = [];
$found_user = $book->user;
$theta = doubleval($found_user['longitude']) - doubleval($_SESSION['longitude']);
$dist = sin(deg2rad(doubleval($found_user['latitude']))) * sin(deg2rad(doubleval($_SESSION['latitude']))) + cos(deg2rad(doubleval($found_user['latitude']))) * cos(deg2rad(doubleval($_SESSION['latitude']))) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = round($dist * 60 * 1.1515 * 1.609344, 1);
$matches['location_name'] = $found_user['location_name'];
$matches['firstname'] = $found_user['name'];
$matches['distance'] = $miles;
$valid_users[] = $matches;
}
// more suggestions based on your location
$suggestions = [];
$more_books = Book::all()->take(100);
foreach ($more_books as $more) {
$matches = [];
$found_user = $more->user;
$theta = doubleval($found_user['longitude']) - doubleval($_SESSION['longitude']);
$dist = sin(deg2rad(doubleval($found_user['latitude']))) * sin(deg2rad(doubleval($_SESSION['latitude']))) + cos(deg2rad(doubleval($found_user['latitude']))) * cos(deg2rad(doubleval($_SESSION['latitude']))) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = round($dist * 60 * 1.1515 * 1.609344, 1);
$matches['location_name'] = $found_user['location_name'];
$matches['firstname'] = $found_user['name'];
$matches['distance'] = $miles;
$matches['title'] = $more->title;
$matches['image'] = $more->image;
$matches['rating'] = $more->rating;
$matches['publisher'] = $more->publisher;
$matches['isbn'] = $more->isbn;
$suggestions[] = $matches;
}
// sort the array based on distance
uasort($valid_users, function ($a) {
return $a['distance'];
});
$valid_users = array_slice($valid_users, 0, 3);
// sort the array based on distance
// uasort($suggestions, function ($b) {
// return $b['distance'];
// });
$suggestions = $this->sort_by_key($suggestions, 'distance');
$suggestions = array_slice($suggestions, 0, 18);
$book = $books[0];
// return $suggestions;
return view("static.foundBooks", compact("valid_users", "book", "suggestions"));
}
}
}
示例15: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$books = Book::all();
return view('index')->withBooks($books);
}