Installation:
composer require djunehor/laravel-bible
Publish the config file (if needed):
php artisan vendor:publish --provider="Djunehor\Bible\BibleServiceProvider"
First Use Case: Fetch a verse (e.g., Genesis 1:1) in a controller or blade template:
use Djunehor\Bible\Facades\Bible;
$verse = Bible::getVerse('Genesis', 1, 1);
return response()->json($verse);
Or in Blade:
{{ Bible::getVerse('Genesis', 1, 1)->text }}
Key Classes:
Bible::getVerse($book, $chapter, $verse) – Core method.Bible::getChapter($book, $chapter) – Fetch entire chapter.Bible::getBooks() – List all books in the Bible.Fetching Verses in Controllers:
public function showVerse(Request $request, $book, $chapter, $verse) {
$verseData = Bible::getVerse($book, $chapter, $verse);
return view('bible.verse', compact('verseData'));
}
Dynamic Verse Lookup (API/Blade): Use route model binding or form inputs:
$book = $request->book;
$chapter = $request->chapter;
$verse = $request->verse;
$data = Bible::getVerse($book, $chapter, $verse);
Bulk Fetching (Chapters/Books):
// Fetch entire Psalms 23
$chapter = Bible::getChapter('Psalms', 23);
// List all books (for dropdowns)
$books = Bible::getBooks();
Integration with Eloquent:
Attach verses to models (e.g., Scripture):
public function store(Request $request) {
$scripture = new Scripture();
$scripture->verse = Bible::getVerse($request->book, $request->chapter, $request->verse)->text;
$scripture->save();
}
Caching Responses: Cache frequent queries (e.g., popular verses):
$verse = Cache::remember("verse_{$book}_{$chapter}_{$verse}", now()->addHours(1), function() use ($book, $chapter, $verse) {
return Bible::getVerse($book, $chapter, $verse);
});
book, chapter, verse) using Laravel’s validation rules:
$validated = $request->validate([
'book' => 'required|in:' . implode(',', array_keys(Bible::getBooks())),
'chapter' => 'required|integer|min:1',
'verse' => 'required|integer|min:1',
]);
resources/lang.Bible facade in unit tests:
$this->mock(Bible::class)->shouldReceive('getVerse')->andReturn((object) ['text' => 'Test verse']);
Case Sensitivity:
Book names are case-sensitive (e.g., Genesis ≠ genesis). Use Bible::getBooks() to get the exact names.
Chapter/Verse Limits: Some books (e.g., Psalms, Proverbs) have irregular chapter/verse counts. Validate inputs to avoid errors:
$maxVerses = Bible::getChapter($book, $chapter)->verses()->count();
$request->validate(['verse' => "required|integer|max:{$maxVerses}"]);
Deprecated Methods: The package is last updated in 2020. Check the source for breaking changes if upgrading Laravel versions.
No Pagination: The package doesn’t support paginating long chapters (e.g., Psalm 119). Handle this manually:
$verses = collect(Bible::getChapter('Psalms', 119)->verses)->chunk(10);
Empty Responses:
Verify inputs match the Bible’s structure (e.g., Revelation has 22 chapters, not 23).
Log the full book list for debugging:
\Log::info('Available books:', ['books' => Bible::getBooks()]);
Performance: Avoid fetching large chapters repeatedly. Cache or preload data:
// Preload all books on app startup (if needed)
app()->booted(function() {
Cache::remember('all_books', now()->addDays(7), function() {
return Bible::getBooks();
});
});
Custom Data Sources:
Override the default data source by binding your own Djunehor\Bible\Contracts\BibleRepository:
$this->app->bind(\Djunehor\Bible\Contracts\BibleRepository::class, function() {
return new CustomBibleRepository();
});
Add Metadata:
Extend the Verse model to include additional fields (e.g., themes, cross-references):
// In a service provider
Bible::extend(function($app) {
$verse = Bible::getVerse('Genesis', 1, 1);
$verse->theme = 'Creation';
return $verse;
});
Search Functionality: Implement a search feature by extending the package or using a separate library (e.g., Bible API):
public function searchVerses($query) {
$results = [];
foreach (Bible::getBooks() as $book) {
$chapter = Bible::getChapter($book, 1);
foreach ($chapter->verses as $verse) {
if (stripos($verse->text, $query) !== false) {
$results[] = (object) [
'book' => $book,
'chapter' => 1,
'verse' => $verse->number,
'text' => $verse->text,
];
}
}
}
return $results;
}
resources/lang/en/bible.php:
return [
'books' => [
'Genesis' => 'Beginning',
// ...
],
];
How can I help you explore Laravel packages today?