/** * Display a listing of the resource. * * @return Response */ public function index() { $users = User::all(); $book_count = Book::all()->count(); $chapter_count = Chapter::all()->count(); return View::make('admin.admin_panel', array('pageTitle' => 'Admin Panel', 'users' => $users, 'book_count' => $book_count, 'chapter_count' => $chapter_count)); }
public static function sandbox() { // Testaa koodiasi täällä //View::make('helloworld.html'); $torakat = Book::find(1); $books = Book::all(); Kint::dump($books); Kint::dump($torakat); }
public function test_delete_by_find_all() { $books = Book::all(); foreach ($books as $model) { $model->delete(); } $res = Book::all(); $this->assert_equals(0, count($res)); }
public static function firstPageBooks() { //now this method searches all the books just like "listingBooks" -method, //but later on (when we have more books in the database), this method wants some //subset of books (like every books that start with "s", or most favourite books or books selected by admin or...) $books = Book::all(); // self::sort_books($books); View::make('general/firstpage.html', array('books' => $books)); }
public function collections() { $collection = Book::all(); //echo Pre::render($collection); # The many faces of a Eloquent Collection object... # Treat it like a string: echo $collection; # Treat it like an array: //foreach($collection as $book) { // echo $book['title']."<br>"; //} # Treat it like an object: //foreach($collection as $book) { // echo $book->title."<br>"; //} }
public function run() { $faker = Faker\Factory::create(); //getting all books from the table $books = Book::all(); $isbn_list = array(); //getting all ISBNs into a single array foreach ($books as $book) { array_push($isbn_list, $book->isbn); } DB::table('library_books')->delete(); for ($i = 0; $i < 15; $i++) { $fake_library_id = $faker->numberBetween(1, 10); $fake_book_isbn = $faker->randomElement($isbn_list); //checking for duplications if (LibraryBooks::where('user_id', '=', $fake_library_id)->where('book_isbn', '=', $fake_book_isbn)->count() > 0) { continue; } LibraryBooks::create(array('user_id' => $fake_library_id, 'book_isbn' => $fake_book_isbn, 'copies_no' => $faker->numerify('##'))); } }
<?php // Modelo de objetos que se corresponde con la tabla de MySQL class Book extends \Illuminate\Database\Eloquent\Model { public $timestamps = false; } // Añadir el resto del código aquí $app->get('/books', function () use($app) { // Creamos un objeto collection + json con la lista de películas // Obtenemos el objeto request, que representa la petición HTTP $req = $app->request; // Obtenemos la ruta absoluta de este recurso $absUrl = $req->getScheme() . "://" . $req->getHost() . $req->getRootUri() . $req->getResourceUri(); // Obtenemos la lista de los libros de la base de datos y la convertimos del formato Json (el devuelto por Eloquent) a un array PHP $libros = json_decode(\Book::all()); $app->view()->setData(array('url' => $absUrl, 'items' => $libros)); // Mostramos la vista $app->render('booklist_template.php'); }); /* Obtención de un libro en concreto */ $app->get('/books/:name', function ($name) use($app) { // Creamos un objeto collection + json con el libro pasado como parámetro // Obtenemos el objeto request, que representa la petición HTTP $req = $app->request; // Obtenemos la ruta absoluta de este recurso $absUrl = $req->getScheme() . "://" . $req->getHost() . $req->getRootUri() . $req->getResourceUri(); // Obtenemos el libro de la base de datos a partir de su id y la convertimos del formato Json (el devuelto por Eloquent) a un array PHP $p = \book::find($name); $libro = json_decode($p); $app->view()->setData(array('url' => preg_replace('/' . preg_quote('/' . $name, '/') . '$/', '', $absUrl), 'item' => $libro));
public function testDeleteByFindAll() { $books = Book::all(); foreach ($books as $model) { $model->delete(); } $res = Book::all(); $this->assertEquals(0, count($res)); }
public function home() { $rs = Book::all(); $data = $rs->toArray(); echo View::getView()->make('home', array('data' => $data))->render(); }
echo "[]"; } }); $app->post('/books', function () use($app) { $title = $app->request->post('title'); $author = $app->request->post('author'); $year = $app->request->post('year'); // Or create a new book $book = new Book(array('title' => $title, 'author' => $author, 'year' => $year)); $book->save(); echo $book->toJson(); }); $app->delete('/books/:id', function ($book_id) use($app) { $book = Book::find($book_id); $book->delete(); $books = Book::all(); echo $books->toJson(); }); $app->put('/books/:id', function ($book_id) use($app) { $title = $app->request->put('title'); $author = $app->request->put('author'); $year = $app->request->put('year'); $book = Book::find($book_id); if ($book != null) { $book->id = $book_id; $book->title = $title; $book->author = $author; $book->year = $year; $book->save(); echo $book->toJson() . $book_id . $title . $author . $year . $book->author . $book->id; //http://stackoverflow.com/questions/23761425/get-put-params-with-slim-php
public function submit() { $books = Book::all(); return $this->response->withCollection($books, new BookTransformer()); }
<?php // Modelo de objetos que se corresponde con la tabla de MySQL class Book extends \Illuminate\Database\Eloquent\Model { public $timestamps = false; } /* Obtención de la lista de libros */ $app->get('/books', function () use($app) { // Creamos un objeto collection + json con la lista de libros // Obtenemos el objeto request, que representa la petición HTTP $req = $app->request; // Obtenemos la ruta absoluta de este recurso $absUrl = $req->getScheme() . "://" . $req->getHost() . $req->getRootUri() . $req->getResourceUri(); // Obtenemos la lista de librosde la base de datos y la convertimos del formato Json (el devuelto por Eloquent) a un array PHP $books = json_decode(\Book::all()); $app->view()->setData(array('url' => $absUrl, 'items' => $books)); // Mostramos la vista $app->render('booklist_template.php'); }); /* Obtención de un libro en concreto */ $app->get('/books/:name', function ($name) use($app) { // Creamos un objeto collection + json con la película pasada como parámetro // Obtenemos el objeto request, que representa la petición HTTP $req = $app->request; // Obtenemos la ruta absoluta de este recurso $absUrl = $req->getScheme() . "://" . $req->getHost() . $req->getRootUri() . $req->getResourceUri(); // Obtenemos la película de la base de datos a partir de su id y la convertimos del formato Json (el devuelto por Eloquent) a un array PHP $p = \Book::find($name); $libro = json_decode($p); $app->view()->setData(array('url' => preg_replace('/' . preg_quote('/' . $name, '/') . '$/', '', $absUrl), 'item' => $libro));
/** * Get all books * * @return Response */ public function index() { $books = Book::all(); return Response::json(['data' => $books]); }
function index() { global $twig; $books = new Book(); echo $twig->render('books_list.html', array('books' => $books->all())); }
public static function index() { $books = Book::all(); Kint::dump($books); View::make('book/index.html', array('books' => $books)); }