This repository is a simple example of how to build a basic CRUD (Create, Read, Update, Delete) application using Laravel 11. It complements the blog post on CRUD operations in Laravel, which will be published on 18th November 2024.
Check out the detailed blog post here: onemoredavid.com/blog/2024-11-18-laravel-crud/
This project demonstrates the basic functionality required to manage a resource—in this case, posts — through a typical CRUD interface. It includes the ability to:
- Create new posts
- List all posts
- View individual posts
- Edit existing posts
- Delete posts
- Laravel 11 for modern PHP application development.
- Uses Eloquent ORM to interact with the database.
- Follows RESTful routing conventions with a resource controller.
- Example of mass assignment protection using
$fillable
.
To run this project locally, follow these steps:
- Clone the repository:
git clone https://github.com/your-username/laravel-crud-example.git
cd laravel-crud-example
- Install dependencies using Composer:
composer install
- Copy the
.env.example
file to.env
and update the database configuration:
cp .env.example .env
- Generate the application key:
php artisan key:generate
- Run the migrations to set up the database:
php artisan migrate
- Serve the application locally:
php artisan serve
Now, you can visit http://localhost:8000/posts
to see the CRUD application in action (or use Laravel Herd, as I do)!
Once the project is running, you can perform the following operations:
- Create a Post: Click on "Create Post" and fill out the form to add a new post.
- View Posts: The home page displays all posts. Click on any post to view its details.
- Edit a Post: On the post's detail page, click "Edit" to modify the post.
- Delete a Post: Use the delete button to remove a post from the database.
For more information on how CRUD works and its role in web applications, check out the supporting blog post: What is CRUD? A Simple Guide with Laravel
This project is open-sourced under the MIT license.