A complete Todo application built with Laravel, demonstrating fundamental web development concepts.
todo-app/
βββ app/
β βββ Http/Controllers/
β β βββ TodoController.php # Main controller
β βββ Models/
β βββ Todo.php # Eloquent model
βββ database/
β βββ migrations/
β βββ create_todos_table.php # Database migration
βββ resources/
β βββ views/
β βββ layouts/
β β βββ app.blade.php # Main layout
β βββ todos/
β βββ index.blade.php # Todo list
β βββ create.blade.php # Creation form
βββ routes/
β βββ web.php # Application routes
βββ README.md # This file
# Clone the project
git clone <repository-url>
cd todo-app
# Install dependencies
composer install
# Copy environment file
cp .env.example .env
# Generate application key
php artisan key:generate
# Configure database in .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=todo_app
DB_USERNAME=root
DB_PASSWORD=
# Run migrations
php artisan migrate
# Start server
php artisan serve
class Todo extends Model
{
protected $fillable = [
'title', 'description', 'completed', 'due_date', 'priority'
];
// Scopes for filtering
public function scopeCompleted($query)
{
return $query->where('completed', true);
}
public function scopePending($query)
{
return $query->where('completed', false);
}
}
class TodoController extends Controller
{
public function index(): View
{
$todos = Todo::latest()->paginate(10);
return view('todos.index', compact('todos'));
}
public function store(Request $request): RedirectResponse
{
$validated = $request->validate([
'title' => 'required|string|max:255',
'priority' => 'required|in:low,medium,high',
]);
Todo::create($validated);
return redirect()->route('todos.index');
}
}
Route::resource('todos', TodoController::class);
Route::patch('/todos/{todo}/toggle', [TodoController::class, 'toggle']);
@extends('layouts.app')
@section('content')
<div class="container">
<div class="card">
<div class="card-header">
<h2><i class="fas fa-tasks"></i> Todo List</h2>
</div>
<div class="card-body">
@foreach($todos as $todo)
<div class="todo-item">
<h5></h5>
<span class="badge bg-">
</span>
</div>
@endforeach
</div>
</div>
</div>
@endsection
create_todos_table.php
$fillable
php artisan migrate:fresh
Edit the file resources/views/layouts/app.blade.php
:
<style>
.card {
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
border-radius: 0.5rem;
}
.todo-item {
border-left: 4px solid #007bff;
padding-left: 1rem;
}
</style>
# Run tests
php artisan test
# Specific tests
php artisan test --filter=TodoTest
class TodoTest extends TestCase
{
public function test_can_create_todo()
{
$response = $this->post('/todos', [
'title' => 'Test Todo',
'priority' => 'medium'
]);
$response->assertRedirect('/todos');
$this->assertDatabaseHas('todos', ['title' => 'Test Todo']);
}
}
# Create Heroku app
heroku create todo-app-laravel
# Configure environment variables
heroku config:set APP_KEY=base64:your-key
heroku config:set DB_CONNECTION=postgresql
# Deploy
git push heroku main
# Run migrations
heroku run php artisan migrate
# Clone the project
git clone <repository-url>
cd todo-app
# Install dependencies
composer install --optimize-autoloader --no-dev
# Configure environment
cp .env.example .env
php artisan key:generate
# Run migrations
php artisan migrate
# Configure web server (Nginx/Apache)
# Optimize for production
php artisan config:cache
php artisan route:cache
php artisan view:cache
The application can be extended with a REST API:
// routes/api.php
Route::apiResource('todos', TodoApiController::class);
Route::patch('todos/{todo}/toggle', [TodoApiController::class, 'toggle']);
GET /api/todos
- List todosPOST /api/todos
- Create a todoGET /api/todos/{id}
- Todo detailsPUT /api/todos/{id}
- Update a todoDELETE /api/todos/{id}
- Delete a todoPATCH /api/todos/{id}/toggle
- Toggle statusgit checkout -b feature/AmazingFeature
)git commit -m 'Add some AmazingFeature'
)git push origin feature/AmazingFeature
)This project is licensed under the MIT License. See the LICENSE
file for details.
For any questions or issues:
Todo Application - Complete Laravel application for task management π―