[{"data":1,"prerenderedAt":26},["ShallowReactive",2],{"article-mastering-laravel-a-step-by-step-guide-to-building-a-todo-application":3},{"id":4,"title":5,"slug":6,"summary":7,"thumbnail":8,"category":9,"tags":15,"categoryId":10,"tagIds":21,"date":22,"updatedAt":22,"views":23,"readingTime":24,"content":25},"ch6F1wfOqR8quoRqBo35","Mastering Laravel: A Step-by-Step Guide to Building a Todo Application","mastering-laravel-a-step-by-step-guide-to-building-a-todo-application","Dive into the world of PHP development by building a functional Todo application with Laravel. This guide covers environment setup, database migrations, and CRUD operations to help you master the fundamentals.","",{"id":10,"description":11,"updatedAt":12,"name":13,"slug":14,"createdAt":12},"Gxt2q3kFYWvJFkbBBB2R","the PHP framework for artisan","2025-12-31T00:34:45.475Z","Laravel","laravel",[16],{"id":17,"name":13,"createdAt":18,"slug":14,"updatedAt":19,"color":20},"U2ARZAP6vtCPeEX2o8ZI","2026-02-16T04:41:46.456Z","2026-06-04T12:55:00.696Z","#ff2d20",[17],"2026-09-23T01:29:09.763Z",1,4,"## Introduction to Laravel\n\nLaravel is widely recognized as one of the most elegant and powerful PHP frameworks available today. Built on the principle of developer happiness, it provides a robust toolkit that simplifies common tasks such as routing, authentication, and database management. For beginners and experienced developers alike, building a Todo application is a rite of passage that offers a comprehensive look at the framework's core features. In this guide, we will walk through the process of creating a fully functional Todo app from scratch.\n\n## Prerequisites\n\nBefore we begin, ensure your development environment is ready. You will need:\n- PHP (version 8.1 or higher)\n- Composer (PHP package manager)\n- Node.js & NPM (for frontend assets)\n- A local database server (MySQL, PostgreSQL, or SQLite)\n\n## Step 1: Project Installation\n\nFirst, open your terminal and run the following command to create a new Laravel project using Composer:\n\n```bash\ncomposer create-project laravel/laravel todo-app\n```\n\nOnce the installation is complete, navigate into the project directory:\n\n```bash\ncd todo-app\n```\n\n## Step 2: Database Configuration\n\nOpen the `.env` file in your project root. Configure your database connection details. For this tutorial, we will assume you are using MySQL:\n\n```env\nDB_CONNECTION=mysql\nDB_HOST=127.0.0.1\nDB_PORT=3306\nDB_DATABASE=todo_db\nDB_USERNAME=root\nDB_PASSWORD=\n```\n\nEnsure you create the `todo_db` database in your MySQL server before proceeding.\n\n## Step 3: Creating the Model and Migration\n\nIn Laravel, models represent the data structure, and migrations handle the database schema. Use the Artisan CLI to generate a Model along with a migration and a controller in one command:\n\n```bash\nphp artisan make:model Task -mc\n```\n\nOpen the newly created migration file in `database/migrations/xxxx_xx_xx_create_tasks_table.php` and define the schema:\n\n```php\npublic function up()\n{\n    Schema::create('tasks', function (Blueprint $table) {\n        $table->id();\n        $table->string('title');\n        $table->boolean('is_completed')->default(false);\n        $table->timestamps();\n    });\n}\n```\n\nRun the migration to create the table:\n\n```bash\nphp artisan migrate\n```\n\n## Step 4: Defining Routes\n\nNavigate to `routes/web.php` and define the routes for our application. We will need routes to view, create, update, and delete tasks:\n\n```php\nuse App\\Http\\Controllers\\TaskController;\nuse Illuminate\\Support\\Facades\\Route;\n\nRoute::get('/', [TaskController::class, 'index'])->name('tasks.index');\nRoute::post('/tasks', [TaskController::class, 'store'])->name('tasks.store');\nRoute::patch('/tasks/{task}', [TaskController::class, 'update'])->name('tasks.update');\nRoute::delete('/tasks/{task}', [TaskController::class, 'destroy'])->name('tasks.destroy');\n```\n\n## Step 5: Implementing Controller Logic\n\nOpen `app/Http/Controllers/TaskController.php`. Here, we will implement the CRUD logic:\n\n```php\nnamespace App\\Http\\Controllers;\n\nuse App\\Models\\Task;\nuse Illuminate\\Http\\Request;\n\nclass TaskController extends Controller\n{\n    public function index() {\n        $tasks = Task::latest()->get();\n        return view('tasks', compact('tasks'));\n    }\n\n    public function store(Request $request) {\n        $request->validate(['title' => 'required|max:255']);\n        Task::create(['title' => $request->title]);\n        return back();\n    }\n\n    public function update(Task $task) {\n        $task->update(['is_completed' => !$task->is_completed]);\n        return back();\n    }\n\n    public function destroy(Task $task) {\n        $task->delete();\n        return back();\n    }\n}\n```\n\n## Step 6: Creating the Frontend (Blade Template)\n\nCreate a file named `tasks.blade.php` inside `resources/views/`. This file will serve as the main interface. For styling, we will use a simple CDN-based CSS framework like Tailwind CSS.\n\n```html\n\u003C!DOCTYPE html>\n\u003Chtml lang=\"en\">\n\u003Chead>\n    \u003Cmeta charset=\"UTF-8\">\n    \u003Ctitle>Laravel Todo App\u003C/title>\n    \u003Cscript src=\"https://cdn.tailwindcss.com\">\u003C/script>\n\u003C/head>\n\u003Cbody class=\"bg-gray-100 p-10\">\n    \u003Cdiv class=\"max-w-md mx-auto bg-white p-6 rounded shadow\">\n        \u003Ch1 class=\"text-2xl font-bold mb-4\">Todo List\u003C/h1>\n        \n        \u003Cform action=\"{{ route('tasks.store') }}\" method=\"POST\" class=\"mb-4\">\n            @csrf\n            \u003Cinput type=\"text\" name=\"title\" class=\"border p-2 w-full\" placeholder=\"New task...\">\n            \u003Cbutton type=\"submit\" class=\"bg-blue-500 text-white p-2 mt-2 w-full\">Add Task\u003C/button>\n        \u003C/form>\n\n        \u003Cul>\n            @foreach($tasks as $task)\n                \u003Cli class=\"flex justify-between items-center border-b py-2\">\n                    \u003Cform action=\"{{ route('tasks.update', $task) }}\" method=\"POST\">\n                        @csrf @method('PATCH')\n                        \u003Cbutton class=\"{{ $task->is_completed ? 'line-through text-gray-400' : '' }}\">\n                            {{ $task->title }}\n                        \u003C/button>\n                    \u003C/form>\n                    \u003Cform action=\"{{ route('tasks.destroy', $task) }}\" method=\"POST\">\n                        @csrf @method('DELETE')\n                        \u003Cbutton class=\"text-red-500\">Delete\u003C/button>\n                    \u003C/form>\n                \u003C/li>\n            @endforeach\n        \u003C/ul>\n    \u003C/div>\n\u003C/body>\n\u003C/html>\n```\n\n## Step 7: Testing the Application\n\nFinally, start the Laravel development server:\n\n```bash\nphp artisan serve\n```\n\nVisit `http://127.0.0.1:8000` in your browser. You can now add tasks, mark them as completed by clicking on the text, and delete them using the delete button.\n\n## Conclusion\n\nCongratulations! You have successfully built a Todo application using Laravel. Through this project, you have learned the fundamentals of the MVC (Model-View-Controller) architecture, database migrations, routing, and Blade templating. Laravel's expressive syntax makes these operations straightforward, allowing you to focus on building features rather than wrestling with boilerplate code. From here, you can extend this app by adding user authentication, categories, or due dates to further enhance your skills.",1790127013355]