https://github.com/noobdevsam/book-store-laravel-project
https://github.com/noobdevsam/book-store-laravel-project
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/noobdevsam/book-store-laravel-project
- Owner: noobdevsam
- Created: 2025-05-20T17:33:10.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-08-06T16:49:39.000Z (10 months ago)
- Last Synced: 2025-08-06T18:36:16.947Z (10 months ago)
- Language: Blade
- Size: 354 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Book Store Laravel Application
A simple Book Store web application built with Laravel and Bootstrap. This project allows users to manage a collection of books, including features for listing, searching, creating, updating, viewing, and deleting books. The UI is styled with Bootstrap 5 for a modern and responsive experience.
---
## 📺 Demo Video
[](https://youtu.be/MxATPW3Ew_E?feature=shared)
> _Click the image above to watch the demo on YouTube!_
---
## Features
- List all books with pagination
- Search books by title or author
- Add new books (with title, author, ISBN, stock, and price)
- Edit existing book details
- View detailed information for each book
- Delete books
- Responsive and clean Bootstrap 5 UI
## Implementation Details
### Book Model
Located at `app/Models/Book.php`:
```php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Book extends Model
{
use HasFactory;
protected $fillable = [
'title', 'author', 'isbn', 'stock', 'price',
];
}
```
### Book Controller
Located at `app/Http/Controllers/BookController.php` (example methods):
```php
namespace App\Http\Controllers;
use App\Models\Book;
use Illuminate\Http\Request;
class BookController extends Controller
{
public function index(Request $request)
{
$search = $request->input('search');
$books = Book::when($search, function ($query, $search) {
return $query->where('title', 'like', "%{$search}%")
->orWhere('author', 'like', "%{$search}%");
})->paginate(50);
return view('books.index', compact('books'));
}
public function store(Request $request)
{
$validated = $request->validate([
'title' => 'required',
'author' => 'required',
'isbn' => 'required',
'stock' => 'required|integer',
'price' => 'required|numeric',
]);
Book::create($validated);
return redirect()->route('books.index')->with('success', 'Book created successfully!');
}
public function show(Book $book)
{
return view('books.show', compact('book'));
}
public function edit(Book $book)
{
return view('books.edit', compact('book'));
}
public function update(Request $request, Book $book)
{
$validated = $request->validate([
'title' => 'required',
'author' => 'required',
'isbn' => 'required',
'stock' => 'required|integer',
'price' => 'required|numeric',
]);
$book->update($validated);
return redirect()->route('books.index')->with('success', 'Book updated successfully!');
}
public function destroy(Book $book)
{
$book->delete();
return redirect()->route('books.index')->with('success', 'Book deleted successfully!');
}
}
```
### Migration Example
Located at `database/migrations/2025_05_12_114522_create_books_table.php`:
```php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up()
{
Schema::create('books', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->string('author');
$table->string('isbn');
$table->integer('stock');
$table->decimal('price', 8, 2);
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('books');
}
};
```
### Blade View Example
Located at `resources/views/books/index.blade.php`:
```blade
@extends('layout')
@section('content')
Bookstore
@if(session('success'))
{{ session('success') }}
@endif
ID
Title
Author
Actions
@foreach($books as $book)
{{ $book->id }}
{{ $book->title }}
{{ $book->author }}
Details
Update
@csrf
@method('DELETE')
Delete
@endforeach
{{ $books->links('pagination::bootstrap-5') }}
@endsection
```
### Routing
Located at `routes/web.php`:
```php
use App\Http\Controllers\BookController;
Route::get('/', function () {
return view('welcome');
});
Route::resource('books', BookController::class);
```
## Getting Started
### Prerequisites
- PHP >= 8.1
- Composer
- SQLite/MySQL/PostgreSQL (default: SQLite)
- Node.js & npm (for frontend assets, optional)
### Installation
1. **Clone the repository:**
```sh
git clone https://github.com/yourusername/book-store.git
cd book-store
```
2. **Install PHP dependencies:**
```sh
composer install
```
3. **Copy and configure environment file:**
```sh
cp .env.example .env
# Edit .env as needed (DB settings, etc.)
```
4. **Generate application key:**
```sh
php artisan key:generate
```
5. **Run migrations and seeders:**
```sh
php artisan migrate --seed
```
6. **(Optional) Install frontend dependencies:**
```sh
npm install && npm run build
```
7. **Start the development server:**
```sh
php artisan serve
```
8. **Visit the app:**
Open [http://localhost:8000/books](http://localhost:8000/books) in your browser.
## Project Structure
- `app/Models/Book.php` - Book Eloquent model
- `app/Http/Controllers/BookController.php` - Controller for book CRUD
- `resources/views/books/` - Blade templates for book pages
- `routes/web.php` - Web routes
- `database/migrations/` - Database schema
- `database/seeders/` - Seeders for sample data
## License
This project is open source and available under the [MIT License](LICENSE).