{"id":18398783,"url":"https://github.com/mongodb-developer/laravel-mongodb-tutorial","last_synced_at":"2025-06-30T09:33:51.745Z","repository":{"id":189798496,"uuid":"679027107","full_name":"mongodb-developer/laravel-mongodb-tutorial","owner":"mongodb-developer","description":"This repository illustrates a tutorial article about how to use MongoDB with Laravel 9 and the Laravel MongoDB package","archived":false,"fork":false,"pushed_at":"2024-07-25T08:01:43.000Z","size":175,"stargazers_count":16,"open_issues_count":1,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-07T05:35:40.363Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mongodb-developer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-16T00:13:03.000Z","updated_at":"2025-02-25T17:23:02.000Z","dependencies_parsed_at":"2023-08-21T20:42:19.146Z","dependency_job_id":"ad9e2b8d-f048-4deb-90f6-6614b45b078f","html_url":"https://github.com/mongodb-developer/laravel-mongodb-tutorial","commit_stats":null,"previous_names":["mongodb-developer/laravel9-mongodb-tutorial","mongodb-developer/laravel-mongodb-tutorial"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mongodb-developer/laravel-mongodb-tutorial","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Flaravel-mongodb-tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Flaravel-mongodb-tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Flaravel-mongodb-tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Flaravel-mongodb-tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mongodb-developer","download_url":"https://codeload.github.com/mongodb-developer/laravel-mongodb-tutorial/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Flaravel-mongodb-tutorial/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262748087,"owners_count":23358106,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T02:24:23.997Z","updated_at":"2025-06-30T09:33:51.706Z","avatar_url":"https://github.com/mongodb-developer.png","language":"PHP","readme":"# How To Build a Laravel + MongoDB Back End Service \n\nThis code was written to accompany [this tutorial article](https://www.mongodb.com/developer/languages/php/laravel-mongodb-tutorial/?utm_campaign=devrel).\n\n## Prerequisites\nYou'll need the following installed on your computer to follow along with this tutorial:\n\n- A MongoDB Atlas cluster \n  - [Create a **free** cluster](https://www.mongodb.com/try?utm_campaign=devrel) and [load the MongoDB sample data](https://www.mongodb.com/basics/sample-database?utm_campaign=devrel).\n- A GitHub account if you want to use GitHub Codespaces (a 1-click experience)\n  - The `master` repo has all the code, but we also have a `starter` branch if you want to follow the project from scratch and build the migrations etc.\n- A code editor of your choice for local development \n  - We suggeest [Visual Studio Code](https://code.visualstudio.com/download). Check the optional [MongoDB for VS Code](https://www.mongodb.com/products/vs-code?utm_campaign=devrel) extension.\n\nThe article mentions several ways to get a Laravel development environment up and running. \n\n#  🚀 Launch this repo in CodeSpaces\n\n\u003cimg src=\"https://i.imgur.com/5STvIPX.png\"\u003e\n\n⏳Codespaces will build the app's container(s). This may take **~3 minutes**.\n\n\u003cimg src=\"https://i.imgur.com/1IBKVjx.png\"\u003e\n\n✅Done! We now have our project running inside CodeSpaces. We can proceed to setting up Laravel\n\n\u003cimg src=\"https://i.imgur.com/9b6P1ba.png\"\u003e\n\n\u003cp\u003e\u003c/p\u003e\u003cp\u003e\u003c/p\u003e\n\n# 👋 Before you run this Laravel app\n\n## 1. Final Laravel app setup\n\nAfter cloning the code repo or launching a Docker/CodeSpaces instance, a script called `init_repo.sh` will be automatically executed (as setup in devcontainer.json) to:\n\n- install dependencies via Composer\n- create a new .env file\n- generate a new Laravel App Key\n\n1. All you need to do is to **add your MongoDB credentials in Laravel's .env file**, using the MONGODB_URI environment variable. Here's [how to get your credentials](https://www.mongodb.com/docs/guides/atlas/connection-string/?utm_campaign=devrel) It looks something like this:\n\n```\nMONGODB_URI=mongodb+srv://USERNAME:PASSWORD@clustername.subdomain.mongodb.net/?retryWrites=true\u0026w=majority\n```\n\n❗Note that this branch already has the Laravel Model and Migrations already created and ready, but the tables have been initialized yet. \n\n2. You can test your credentials by using the code's API endpoint\n\n```\n\u003csiteroot\u003e/api/test_mongodb/\n```\n\nFind the site's root URL by going to the \"Ports\" tab and click on the globe icon of port 80\n\n\u003cimg src=\"https://i.imgur.com/pkORDBj.png\"\u003e\n\n3. If the MongoDB ping test worked, use this command in the terminal to initialize the tables\n\n`php artisan migrate:refresh`\n\n\u003cp\u003e\u003c/p\u003e\n\n## 2. Ready!\n\n\u003cimg src=\"https://i.imgur.com/fbZlygD.png\"\u003e\n\nOur base Laravel app is ready 🥳. \n\n**Next**, try some of the things we talked about in our [How To Build a Laravel + MongoDB Back End Service](https://www.mongodb.com/developer/languages/php/laravel-mongodb-tutorial/)\n\n#  🚀 Launch locally with Docker\n\nAssuming that you already have Docker Desktop installed on Windows/Mac or Docker on Linux,\n\n- clone the repository to a local directory\n- navigate to the ./devcontainer folder\n- execute `docker compose up`\n- in the PHP container, execute `sh init_repo.sh`\n- initialize your .env file as instructed above\n\nOnce the container(s) are up, visit http://localhost\n\n# Optional: Xdebug\n\nThe xdebug.php-debug VS Code extension is automatically installed if you launch via devcontainer.json.\n\n👀 **Important**: our `.devcontainer/.docker/php/xdebug.ini` file is setup by default with `xdebug.client_host=localhost`, which should works for **CodeSpaces** and Devcontainers. \n\nFor **local development**, you need to replace `localhost` with the IP where your code IDE runs or a dns name that maps to it. That's because your PHP container and the IDE host tend to have different IPs. \n\nIf you are using our container directly (docker compose up), or via VS Code (devcontainer), we suggest the following Xdebug configs visual studio. Note the difference in path mapping.\n\n## CodeSpaces and (inside a Devcontainer)\n\n```json\n{\n  \"name\": \"Listen for Xdebug\",\n  \"type\": \"php\",\n  \"request\": \"launch\",\n  \"port\": 9003,\n  \"pathMappings\":  {\n    \"/var/www/htdoc\": \"${workspaceFolder}\"\n  }\n},\n```\n\n## local development with Docker\n\nThe debug config file is located in `\u003crepository_dir\u003e/.vscode/launch.json`\n\n```json\n{\n  \"name\": \"Listen for Xdebug\",\n  \"type\": \"php\",\n  \"request\": \"launch\",\n  \"port\": 9003,\n  \"pathMappings\":  {\n    \"/var/www/htdoc\": \"${workspaceFolder}/src\"\n  }\n},\n```\n\n# Disclaimer\n\nUse at your own risk; not a supported MongoDB product\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongodb-developer%2Flaravel-mongodb-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmongodb-developer%2Flaravel-mongodb-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongodb-developer%2Flaravel-mongodb-tutorial/lists"}