Skip to content

Emmanuel-W/laravelCRUD

Repository files navigation

Laravel CRUD Application

A simple, full-featured CRUD (Create, Read, Update, Delete) application built with Laravel 11, Blade templating engine, and SQLite database. This project demonstrates fundamental web development patterns including MVC architecture, RESTful routing, form validation, and database operations.

Project Overview

This application provides a complete item management system where users can:

  • Create new items with name, description, and optional price
  • Read and browse all items in a paginated table view
  • Update existing item information
  • Delete items with a confirmation dialog
  • View detailed information about individual items

The application follows Laravel's conventions and best practices, making it an excellent starting point for learning Laravel development or as a foundation for more complex applications.

Key Features

  • ✅ Full CRUD operations (Create, Read, Update, Delete)
  • ✅ Form validation with error handling
  • ✅ Pagination for large datasets
  • ✅ Responsive Bootstrap 5 UI
  • ✅ SQLite database (no external database server required)
  • ✅ RESTful routing
  • ✅ MVC architecture
  • ✅ Success/error flash messages
  • ✅ Confirmation dialogs for destructive actions

Project Setup Instructions

Prerequisites

Before you begin, ensure you have the following installed on your system:

  • PHP 8.2 or higher - Check with php -v
  • Composer - PHP dependency manager (Download Composer)
  • SQLite - Usually included with PHP installations

Step 1: Clone or Download the Project

If you have the project files, navigate to the project directory:

cd laravelcrudapp

Step 2: Install Dependencies

Install all PHP dependencies using Composer:

composer install

This will install Laravel framework and all required packages.

Step 3: Environment Configuration

The project comes pre-configured with SQLite. The database file (database/database.sqlite) should already exist. If it doesn't, create it:

touch database/database.sqlite

Or on Windows:

type nul > database\database.sqlite

Step 4: Run Migrations

The database migrations have already been run, but if you need to reset or run them again:

php artisan migrate

This will create the items table in your SQLite database.

Step 5: Start the Development Server

Start Laravel's built-in development server:

php artisan serve

The server will start on http://localhost:8000 by default.

Step 6: Access the Application

Open your web browser and navigate to:

http://localhost:8000

You will be automatically redirected to /items which displays the items list.

Optional: Generate Application Key

If you encounter any issues, you may need to generate an application key:

php artisan key:generate

Design Choices

1. Laravel Framework Selection

Why Laravel 11?

  • Modern PHP Framework: Laravel is one of the most popular and well-documented PHP frameworks
  • Built-in Features: Provides authentication, validation, routing, and ORM out of the box
  • Developer Experience: Excellent tooling with Artisan CLI, clear error messages, and comprehensive documentation
  • Community Support: Large community and extensive package ecosystem
  • MVC Architecture: Enforces clean separation of concerns

2. Blade Templating Engine

Why Blade instead of a frontend framework?

  • Server-Side Rendering: Simple and efficient for CRUD applications
  • No Build Step: No need for npm, webpack, or build processes
  • Laravel Integration: Native integration with Laravel's features (routes, models, etc.)
  • Learning Curve: Easier for developers familiar with PHP/HTML
  • Performance: Direct rendering without JavaScript overhead for simple applications

3. SQLite Database

Why SQLite instead of MySQL/PostgreSQL?

  • Zero Configuration: No need to set up a separate database server
  • Portability: Database is a single file (database.sqlite)
  • Perfect for Development: Ideal for small to medium applications
  • Easy Deployment: No database server dependencies
  • Learning: Simplifies the setup process for beginners

Trade-off: SQLite is not ideal for high-concurrency production applications, but perfect for this CRUD demonstration.

4. RESTful Resource Controller

Why use Resource Controllers?

  • Convention over Configuration: Laravel's standard approach
  • Clean Code: All CRUD methods in one controller
  • RESTful Routes: Follows REST principles (GET /items, POST /items, etc.)
  • Maintainability: Easy to understand and modify
  • Scalability: Easy to add more resources following the same pattern

5. Bootstrap 5 for Styling

Why Bootstrap instead of Tailwind CSS or custom CSS?

  • Rapid Development: Pre-built components (tables, forms, buttons, alerts)
  • Consistency: Ensures a professional look without custom CSS
  • Responsive: Built-in responsive design
  • CDN Delivery: Easy to include via CDN
  • Familiar: Most developers are familiar with Bootstrap

Note: Laravel 11 ships with Tailwind CSS, but Bootstrap was chosen for faster development and simpler styling.

6. Form Validation

Why server-side validation?

  • Security: Never trust user input - validate on the server
  • Data Integrity: Ensures database constraints are met
  • User Feedback: Clear error messages guide users
  • Laravel's Validation: Powerful, expressive validation rules

7. Pagination

Why paginate results?

  • Performance: Prevents loading thousands of records at once
  • User Experience: Easier to navigate large datasets
  • Memory Efficiency: Reduces server memory usage
  • Laravel Built-in: Simple pagination with paginate() method

8. Flash Messages

Why use session flash messages?

  • User Feedback: Immediate confirmation of actions
  • Non-intrusive: Doesn't require page reloads or JavaScript
  • Laravel Sessions: Built-in session management
  • UX Best Practice: Standard pattern for web applications

9. Route Model Binding

Why use Route Model Binding?

  • Clean URLs: /items/{item} instead of /items/{id}
  • Automatic Resolution: Laravel automatically finds the model
  • 404 Handling: Automatic 404 if item doesn't exist
  • Type Safety: Type-hinted models in controller methods
  • Less Code: No need to manually query the database

10. MVC Architecture

Why follow MVC pattern?

  • Separation of Concerns: Models (data), Views (presentation), Controllers (logic)
  • Maintainability: Easy to locate and modify code
  • Testability: Each component can be tested independently
  • Scalability: Easy to add features without breaking existing code
  • Team Collaboration: Multiple developers can work on different components

Project Structure

laravelcrudapp/
├── app/
│   ├── Http/
│   │   └── Controllers/
│   │       └── ItemController.php    # Handles all CRUD operations
│   └── Models/
│       └── Item.php                   # Item model with fillable fields
├── database/
│   ├── migrations/
│   │   └── *_create_items_table.php  # Database schema
│   └── database.sqlite               # SQLite database file
├── resources/
│   └── views/
│       ├── layouts/
│       │   └── app.blade.php         # Main layout template
│       └── items/
│           ├── index.blade.php       # List all items
│           ├── create.blade.php      # Create form
│           ├── edit.blade.php        # Edit form
│           └── show.blade.php        # View single item
├── routes/
│   └── web.php                       # Application routes
└── README.md                         # This file

Database Schema

The items table structure:

Column Type Constraints
id bigint Primary Key, Auto Increment
name varchar(255) Required
description text Nullable
price decimal(10,2) Nullable
created_at timestamp Auto-managed
updated_at timestamp Auto-managed

Routes

Method URI Action Description
GET / redirect Redirects to items index
GET /items index List all items (paginated)
GET /items/create create Show create form
POST /items store Save new item
GET /items/{item} show Display single item
GET /items/{item}/edit edit Show edit form
PUT /items/{item} update Update existing item
DELETE /items/{item} destroy Delete item

Technologies Used

  • Laravel 11 - PHP web framework
  • Blade - Laravel's templating engine
  • SQLite - Lightweight database
  • Bootstrap 5 - CSS framework for styling
  • PHP 8.2+ - Programming language

Future Enhancements

Potential improvements for this application:

  • User authentication and authorization
  • Image uploads for items
  • Search and filtering functionality
  • Sorting by columns
  • Export to CSV/Excel
  • API endpoints for mobile apps
  • Unit and feature tests
  • Docker containerization
  • Category/tag system
  • Soft deletes (trash/recycle bin)

License

This project is open-source and available for educational purposes.

Contributing

Feel free to fork this project and submit pull requests for any improvements!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages