Ejemplo n.º 1
0
 /**
  * Get all books
  * if no limit specified, a default number 50 is filtered
  *
  * @return \Illuminate\Database\Eloquent\Collection|static[]
  */
 public function all()
 {
     $limit = input('limit', 50);
     $books = Book::all()->take($limit);
     event(new ExampleEvent());
     return $books;
 }
 public function bookItemWithTransformer()
 {
     $fractal = new Manager();
     $book = Book::all()->random(1);
     //$book = Book::find(1);
     $resource = new Item($book, new BookTransformer());
     return $fractal->createData($resource)->toJson();
 }
Ejemplo n.º 3
0
 public function index()
 {
     if ($this->petugas == null) {
         header("Location: " . base . "/Auth");
         exit;
     }
     $books = Book::all();
     $this->view->render('admin/book', ['books' => $books, 'petugas' => $this->petugas]);
 }
 public function index()
 {
     if (auth()->user()->can('book_manage_all')) {
         $books = Book::all();
     } else {
         $books = Book::whereUserId(auth()->user()->id)->get();
     }
     return view('admin.books.index', compact('books'));
 }
Ejemplo n.º 5
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     return response(['books' => Book::all()], 200);
 }
Ejemplo n.º 6
0
});
$app->post('/authors', function (Request $request) use($app) {
    $this->validate($request, Author::VALIDATION_RULES);
    $new_author = new Author($request->all());
    $new_author->save();
    return redirect('authors/' . $new_author->id);
});
$app->post('/authors/{id}/update', function ($id, Request $request) {
    $this->validate($request, Author::VALIDATION_RULES);
    $author = Author::find($id);
    $author->update($request->all());
    return redirect('authors/' . $author->id);
});
// --- BOOKS ---
$app->get('/books', function () use($app) {
    $books = Book::all();
    return view('books.index', ['books' => $books]);
});
$app->get('/books/new', function (Request $request) use($app) {
    $authors = Author::all();
    return view('books.new', ['authors' => $authors, 'request' => $request]);
});
$app->post('/books', function (Request $request) use($app) {
    $this->validate($request, Book::VALIDATION_RULES);
    $new_book = new Book($request->all());
    $new_book->save();
    return redirect('books/' . $new_book->id);
});
$app->get('/books/{id}', function ($id, Request $request) use($app) {
    $book = Book::find($id);
    $authors = Author::all();