Laravel version - 11.22.0
Php version - 8.3
Setup
- composer create-project laravel/laravel laraproject
- sudo pecl install mongodb
- Find php.in and modify it.
- phpinfo() or php -i will give location of php.ini
- Append the file to add at the bottom - extension="mongodb.so"
- composer require mongodb/laravel-mongodb
-
modify the file 'config\database.php' to add the following
'mongodb' => [
'driver' => 'mongodb',
'dsn' => env('DB_URI', 'mongodb://localhost:27017/db_name'),
'database' => env('DB_DATABASE', 'db_name'),
],
-
Set the default database connection name in config\database.php