Skip to content

This repository illustrates a tutorial article about how to use MongoDB with Laravel 9 and the Laravel MongoDB package

Notifications You must be signed in to change notification settings

mongodb-developer/laravel-mongodb-tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How To Build a Laravel + MongoDB Back End Service

This code was writting in conjunction with this article.

Prerequisites

You'll need the following installed on your computer to follow along with this tutorial:

The article mentions several ways to get a Laravel development environment up and running.

Preparing the Laravel project to run

Before the project can run properly, we need to take several actions.

1. Install dependencies

In the Laravel project folder, install the Composer dependencies with the command

composer install

2. Create the .env file

Laravel uses the .env file for environment-specific configurations, like database credentials, application key, and other settings. Create one from the included example file:

cp .env.example .env

3. Generate a Laravel Application key

Laravel might ask to generate a new application key. You can do it by running this command in the laravel project folder.

php artisan key:generate

4. Add the MongoDB connection string to .env

We need to add the MongoDB connection string with the username / password to the .env file. add this line, but remember that your connection string might look different.

DB_URI=mongodb+srv://USERNAME:PASSWORD@clustername.subdomain.mongodb.net/?retryWrites=true&w=majority

5. Ready!

Head to the site URL and you should see the Laravel Homepage

Xdebug

The xdebug.php-debug VS Code extension is automatically installed if you launch via devcontainer.json.

If you are using our container directly (docker compose up), or via VS Code (devcontainer), we suggest the following Xdebug configs visual studio

localhost

The debug config file is located in <repository_dir>/.vscode/launch.json

{
  "name": "Listen for Xdebug",
  "type": "php",
  "request": "launch",
  "port": 9003,
  "pathMappings":  {
    // ${workspaceFolder} == directory where /.vscode/ is
    // the syntax is SERVER_PATH : LOCAL_PATH
    "/var/www/htdoc": "${workspaceFolder}/src"
  }
},

devcontainer

  • TODO

Codespaces

  • TODO

Disclaimer

Use at your own risk; not a supported MongoDB product

About

This repository illustrates a tutorial article about how to use MongoDB with Laravel 9 and the Laravel MongoDB package

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •