
How to Build a Task Reminder App with Laravel and MongoDB
Staying organized is everything, especially in a world full of distractions. Whether you’re working solo or managing a small team, having a personal task reminder can seriously boost your productivity. In this guide, I’ll walk you through building one using Laravel and MongoDB a combo that’s fast, flexible, and surprisingly fun to work with.
Why Laravel + MongoDB?
Laravel’s syntax is elegant, expressive, and packed with tools that make building apps a breeze. But if your data is more dynamic say, not every record has the exact same structure, MongoDB becomes a perfect fit. It’s a NoSQL document database, which means it stores data in flexible JSON like documents.
Put simply: Laravel keeps things beautiful. MongoDB keeps things flexible.
Prerequisites
Before we dive in, make sure you have:
- PHP 8.x or later
- Composer
- MongoDB running locally or using MongoDB Atlas
- Laravel installed (
composer create-project laravel/laravel
) - MongoDB PHP driver installed (
pecl install mongodb
) - Laravel MongoDB package (
mongodb/laravel-mongodb
)
Once MongoDB is installed, make sure to enable it in your php.ini
:
extension=mongodb.so
Then restart your server (Valet/XAMPP/etc).
Step 1: Create the Laravel Project
If you haven’t yet, create your Laravel app:
composer create-project laravel/laravel task-reminder
Now install the MongoDB Laravel package:
composer require mongodb/laravel-mongodb
Step 2: Configure MongoDB in Laravel
In config/database.php
, add a new connection like this:
'mongodb' => [
'driver' => 'mongodb',
'dsn' => env('MONGODB_URI', 'mongodb://localhost:27017'),
'database' => env('MONGODB_DATABASE', 'task_reminder'),
],
Then, update your .env
file:
DB_CONNECTION=mongodb
MONGODB_URI=mongodb://localhost:27017
MONGODB_DATABASE=task_reminder
Nice! Now Laravel is ready to talk to MongoDB.
Step 3: Create the Task Model
Let’s create a model for tasks:
php artisan make:model Task
Then update the model to use the MongoDB Eloquent base:
use MongoDB\Laravel\Eloquent\Model;
class Task extends Model
{
protected $connection = 'mongodb';
protected $collection = 'tasks';
protected $fillable = [
'title',
'description',
'due_date',
'is_completed',
];
}
Step 4: Build the Controller
Let’s create a controller to handle task logic:
php artisan make:controller TaskController
Fill it with the basic CRUD functions:
public function index() {
return Task::all();
}
public function store(Request $request) {
return Task::create($request->all());
}
public function update(Request $request, $id) {
$task = Task::find($id);
$task->update($request->all());
return $task;
}
public function destroy($id) {
Task::destroy($id);
return response()->json(['message' => 'Deleted']);
}
Step 5: Define the Routes
In routes/api.php
, register the API routes:
use App\Http\Controllers\TaskController;
Route::apiResource('tasks', TaskController::class);
Step 6: Add Task Reminders with Notifications
Let’s send email reminders 1 day before due date.
Generate the notification:
php artisan make:notification TaskReminder
In the notification class:
public function toMail($notifiable) {
return (new MailMessage)
->subject('Reminder: Task Due Soon')
->line('Your task "' . $this->task->title . '" is due tomorrow!')
->line('Don’t forget to complete it!');
}
Schedule a command in App\Console\Kernel.php
:
protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
$tasks = Task::whereDate('due_date', now()->addDay()->toDateString())->get();
foreach ($tasks as $task) {
$task->user->notify(new TaskReminder($task));
}
})->daily();
}
Step 7: Polish & Deploy
Before pushing live:
- Set
APP_ENV=production
- Set proper file/folder permissions
- Set up a CRON job for
php artisan schedule:run
- Optionally, secure API routes with authentication
Final Thoughts
Building a task reminder app with Laravel and MongoDB is surprisingly smooth once you get the hang of it. You get the elegance of Laravel’s ecosystem routing, notifications, and queues mixed with the schema-less power of MongoDB. Whether it’s a personal productivity tool or a feature for your SaaS, this setup can scale easily.
If you’re used to SQL, MongoDB might feel weird at first. But for apps with flexible or changing structures, it’s a total win.
Pro Tip: Store user timezone preferences and send reminders at their local time using Laravel Jobs + Carbon::parse()->timezone($user->tz)
.