1. Go to this page and download the library: Download threeleaf/biblioteca library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
threeleaf / biblioteca example snippets
use ThreeLeaf\Biblioteca\Models\Author;
use ThreeLeaf\Biblioteca\Models\Book;
$author = Author::create([
'first_name' => 'John',
'last_name' => 'Marsh',
'biography' => 'John Marsh is a prolific writer...',
]);
$book = Book::create([
'title' => 'The Great Adventure',
'author_id' => $author->author_id,
'published_date' => now(),
'summary' => 'A thrilling tale of adventure...',
]);
$bookAuthor = $book->author;
echo "Book Author: $bookAuthor->first_name $bookAuthor->last_name";
use ThreeLeaf\Biblioteca\Models\Chapter;
use ThreeLeaf\Biblioteca\Models\Paragraph;
$chapter = Chapter::create([
'book_id' => $book->book_id,
'chapter_number' => 1,
'title' => 'Chapter 1: The Beginning',
]);
$paragraph = Paragraph::create([
'chapter_id' => $chapter->chapter_id,
'paragraph_number' => 1,
'content' => 'This is the first paragraph of the chapter...',
]);
/* Retrieve all books by a specific author */
$booksByAuthor = Author::find($author->author_id)->books;
foreach ($booksByAuthor as $book) {
echo $book->title;
}
use App\Http\Controllers\AuthorController;
Route::apiResource('authors', AuthorController::class);