A Laravel application pre-configured with MongoDB integration, complete with authentication system and user management functionality. This starter kit provides all the necessary configurations and components to quickly build Laravel applications with MongoDB as the database.
- Laravel 12 - Latest version of the Laravel framework
- MongoDB Integration - Seamless MongoDB database connection using
mongodb/laravel-mongodb
- Authentication System - Complete auth flow with Laravel Breeze
- User Management - CRUD operations for user administration
- Email Verification - Built-in email verification system
- Password Reset - Secure password reset functionality
- Profile Management - User profile editing capabilities
- Pre-configured Models & Controllers - Ready-to-use User model and authentication controllers
- PHP 8.2 or higher
- MongoDB extension (
ext-mongodb
) - MongoDB server (local or cloud)
- Composer
Create a new Laravel project using this starter kit:
composer create-project mongodb-developer/laravel-with-mongodb-starter-kit my-project
cd my-project
This starter kit comes with the following pre-configured components:
The MongoDB connection is already configured in config/database.php
:
'mongodb' => [
'driver' => 'mongodb',
'dsn' => env('MONGODB_URI', 'mongodb://localhost:27017'),
'database' => env('MONGODB_DATABASE', 'laravel_app'),
],
The .env.example
file includes MongoDB-specific configuration:
###> mongodb/laravel-mongodb ###
# DB_CONNECTION=mongodb
# Format described at https://www.mongodb.com/docs/php-library/current/connect/connection-options/
# MONGODB_URI="mongodb://username:password@localhost:27017/?authSource=auth-db"
# MONGODB_URI="mongodb+srv://username:password@YOUR_CLUSTER_NAME.YOUR_HASH.mongodb.net/?retryWrites=true&w=majority"
# MONGODB_DATABASE="test"
Pre-configured User model (app/Models/User.php
) with MongoDB support:
<?php
namespace App\Models;
use Illuminate\Auth\Authenticatable;
use MongoDB\Laravel\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Notifications\Notifiable;
class User extends Model implements AuthenticatableContract
{
use Notifiable, Authenticatable;
protected $connection = 'mongodb';
protected $collection = 'users';
protected $fillable = [
'name',
'email',
'password',
];
protected $hidden = [
'password',
'remember_token',
];
}
Complete set of authentication controllers in app/Http/Controllers/Auth/
:
AuthenticatedSessionController.php
- Login/logout functionalityRegisteredUserController.php
- User registrationPasswordResetLinkController.php
- Password reset linksNewPasswordController.php
- Password reset handlingEmailVerificationPromptController.php
- Email verificationConfirmablePasswordController.php
- Password confirmation- And more...
UserController.php
with full CRUD operations:
class UserController extends Controller
{
public function index() // List all users
public function edit(User $user) // Show edit form
public function update(Request $request, User $user) // Save changes
public function destroy(User $user) // Delete user
}
ProfileController.php
for user profile management:
class ProfileController extends Controller
{
public function edit(Request $request) // Display profile form
public function update(ProfileUpdateRequest $request) // Update profile
public function destroy(Request $request) // Delete account
}
php artisan key:generate
Update your .env
file with your MongoDB connection details:
For Local MongoDB:
DB_CONNECTION=mongodb
MONGODB_URI=mongodb://localhost:27017
MONGODB_DATABASE=your_database_name
For MongoDB Atlas:
DB_CONNECTION=mongodb
MONGODB_URI=mongodb+srv://username:password@YOUR_CLUSTER_NAME.YOUR_HASH.mongodb.net/?retryWrites=true&w=majority
MONGODB_DATABASE=your_database_name
php artisan serve
GET /#
- Login pagePOST /#
- Process loginGET /register
- Registration pagePOST /register
- Process registrationPOST /logout
- Logout userGET /forgot-password
- Password reset requestPOST /forgot-password
- Send reset linkGET /reset-password/{token}
- Password reset formPOST /reset-password
- Process password reset
GET /users
- List all usersGET /users/{user}/edit
- Edit user formPUT /users/{user}
- Update userDELETE /users/{user}
- Delete user
GET /profile
- View profilePATCH /profile
- Update profileDELETE /profile
- Delete account
Complete authentication flow with:
- User registration with email verification
- Secure login with rate limiting
- Password reset functionality
- Remember me functionality
- Session management
Administrative interface for:
- Viewing all users
- Editing user information
- Deleting users
- Email verification for new registrations
- Password reset emails
- Configurable mail settings
- Password hashing with bcrypt
- CSRF protection
- Rate limiting on login attempts
- Secure session handling
- Input validation
This starter kit provides:
Database Configuration - MongoDB connection ready to use
User Model - MongoDB-compatible User model with authentication
Authentication Controllers - Complete auth flow (login, register, password reset, etc.)
User Management - CRUD operations for user administration
Profile Management - User profile editing capabilities
Form Requests - Validation classes for user input
Routes - Pre-defined routes for all functionality
Security - Built-in security features and rate limiting
For learning more about integration MongoDB in Laravel applications, refer to the official Laravel Documentations.
Start building your Laravel + MongoDB-powered application!