aasawari.sahasrabuddhe / laravel-with-mongodb-starter-kit
A Laravel application pre-configured with MongoDB integration
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Language:Blade
Type:project
Requires
- php: ^8.2
- ext-mongodb: ^1.21|^2
- laravel/framework: ^12.0
- laravel/tinker: ^2.10.1
- mongodb/laravel-mongodb: ^5.4
Requires (Dev)
- fakerphp/faker: ^1.23
- laravel/pail: ^1.2.2
- laravel/pint: ^1.13
- laravel/sail: ^1.41
- mockery/mockery: ^1.6
- nunomaduro/collision: ^8.6
- pestphp/pest: ^3.8
- pestphp/pest-plugin-laravel: ^3.2
README
This starter kit provides a ready-to-use Laravel setup configured to use MongoDB as the primary database. It simplifies the initial configuration so you can get started with building Laravel apps using MongoDB right away.
Prerequisites
Before using this starter kit, make sure the following dependencies are installed on your machine:
1. Install PHP
Make sure PHP is installed (version 8.1 or higher recommended).
php -v
If not installed, follow instructions on php.net to install PHP on your system.
2. Install MongoDB Extension for PHP
Use PECL to install the MongoDB driver:
pecl install mongodb
✅ You may need to enable the extension in your
php.ini
file:
extension=mongodb.so
For more details, refer to the official MongoDB PHP driver documentation.
Create a New Laravel Project Using the Starter Kit
Run the following command to create a new Laravel project with MongoDB support:
laravel new your-app-name --using=mongodb-developer/laravel-with-mongodb-starter-kit
This command will scaffold a Laravel project with MongoDB configured out of the box.
⚙️ Configuration Details
config/database.php
The starter kit sets the default database connection to MongoDB and adds a connection config block:
'default' => env('DB_CONNECTION', 'mongodb'), 'mongodb' => [ 'driver' => 'mongodb', 'dsn' => env('MONGODB_URI', 'mongodb://localhost:27017'), 'database' => env('MONGODB_DATABASE', 'laravel_app'), ],
.env.example
The .env.example
file includes sample environment variables for MongoDB:
###> 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" ###< mongodb/laravel-mongodb ###
You can update these values in your .env
file to point to your local or cloud MongoDB instance.
✅ You're All Set!
After setting the correct MongoDB credentials in your .env
, you can now run the Laravel app:
php artisan serve
Start building your Laravel + MongoDB-powered application!
For learn more about integrating MongoDB in Laravel applications, refer to the official MongoDB Documentations.