You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+72-29Lines changed: 72 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# How To Build a Laravel + MongoDB Back End Service
2
2
3
-
This code was writting in conjunction with[this article](https://www.mongodb.com/developer/languages/php/laravel-mongodb-tutorial/?utm_campaign=devrel).
3
+
This code was writting to accompany[this article](https://www.mongodb.com/developer/languages/php/laravel-mongodb-tutorial/?utm_campaign=devrel).
4
4
5
5
6
6
## Prerequisites
@@ -13,47 +13,85 @@ You'll need the following installed on your computer to follow along with this t
13
13
14
14
The article mentions several ways to get a Laravel development environment up and running.
15
15
16
-
# Preparing the Laravel project to run
16
+
# 🚀 Launch this repo in CodeSpaces
17
17
18
-
Before the project can run properly, we need to take several actions.
18
+
<imgsrc="https://i.imgur.com/5STvIPX.png">
19
19
20
-
## 1. Install dependencies
20
+
⏳Codespaces will build the app's container(s). This may take **~3 minutes**.
21
21
22
-
In the Laravel project folder, install the Composer dependencies with the command
22
+
<imgsrc="https://i.imgur.com/1IBKVjx.png">
23
23
24
-
`composer install`
24
+
✅Done! We now have our project running inside CodeSpaces. We can proceed to setting up Laravel
25
25
26
-
## 2. Create the .env file
26
+
<imgsrc="https://i.imgur.com/9b6P1ba.png">
27
27
28
-
Laravel uses the .env file for environment-specific configurations, like database credentials, application key, and other settings. Create one from the included example file:
28
+
<p></p><p></p>
29
29
30
-
`cp .env.example .env`
30
+
# 👋 Before you run this Laravel app
31
31
32
-
## 3. Generate a Laravel Application key
32
+
## 1. Laravel setup
33
33
34
-
Laravel might ask to generate a new application key. You can do it by running this command in the laravel project folder.
34
+
After cloning the code repo or launching a Docker/CodeSpaces instance, the project needs a few more things before the Laravel App can run:
35
35
36
-
`php artisan key:generate`
36
+
1. install dependencies via Composer
37
+
2. create a new .env file
38
+
3. generate a new Laravel App Key
37
39
38
-
## 4. Add the MongoDB connection string to .env
40
+
You can conveniently do all three by running the `init_repo.sh` from the
41
+
PHP container.
39
42
40
-
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.
The script will install the package via Composer, create an .env and create an App key.
46
+
47
+
<imgsrc="https://i.imgur.com/6P6MlFX.png">
43
48
44
-
## 5. Ready!
49
+
## 2. Ready!
45
50
46
51
Head to the site URL and you should see the Laravel Homepage
47
52
48
-
# Xdebug
53
+
<imgsrc="https://i.imgur.com/pkORDBj.png">
54
+
55
+
<p></p>
56
+
57
+
<imgsrc="https://i.imgur.com/fbZlygD.png">
58
+
59
+
Our base Laravel app is ready 🥳.
60
+
61
+
❗Note that this branch already has the Model and Migrations already setup.
62
+
63
+
64
+
**Next**, you can connect to a MongoDB Cluster and 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/)
65
+
66
+
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.
Assuming that you already have Docker Desktop installed on Windows/Mac or Docker on Linux,
75
+
76
+
- clone the repository to a local directory
77
+
- navigate to the ./devcontainer folder
78
+
- execute `docker compose up`
79
+
- in the PHP container, execute the init_repo.sh script
80
+
81
+
Once the containe(s) are up, visit http://localhost
82
+
83
+
84
+
# Optional: Xdebug
49
85
50
86
The xdebug.php-debug VS Code extension is automatically installed if you launch via devcontainer.json.
51
87
52
-
If you are using our container directly (docker compose up), or via VS Code (devcontainer), we suggest the following Xdebug configs visual studio
88
+
👀 **Important**: our `.devcontainer/.docker/php/xdebug.ini` file is setup by default with `xdebug.client_host=localhost`, which should works for **CodeSpaces** and Devcontainers.
53
89
54
-
### localhost
90
+
For **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.
55
91
56
-
The debug config file is located in `<repository_dir>/.vscode/launch.json`
92
+
If 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.
93
+
94
+
## CodeSpaces and (inside a Devcontainer)
57
95
58
96
```json
59
97
{
@@ -62,21 +100,26 @@ The debug config file is located in `<repository_dir>/.vscode/launch.json`
62
100
"request": "launch",
63
101
"port": 9003,
64
102
"pathMappings": {
65
-
// ${workspaceFolder} == directory where /.vscode/ is
66
-
// the syntax is SERVER_PATH : LOCAL_PATH
67
-
"/var/www/htdoc": "${workspaceFolder}/src"
103
+
"/var/www/htdoc": "${workspaceFolder}"
68
104
}
69
105
},
70
106
```
71
107
72
-
### devcontainer
73
-
74
-
- TODO
75
-
76
-
### Codespaces
108
+
## local development with Docker
77
109
78
-
- TODO
110
+
The debug config file is located in `<repository_dir>/.vscode/launch.json`
0 commit comments