forked from mongodb/laravel-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.txt
82 lines (60 loc) · 2.21 KB
/
install.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
.. _laravel-install:
===============
Getting Started
===============
.. facet::
:name: genre
:values: tutorial
.. meta::
:keywords: php framework, odm, code example
Installation
------------
Make sure you have the MongoDB PHP driver installed. You can find installation
instructions at `https://php.net/manual/en/mongodb.installation.php <https://php.net/manual/en/mongodb.installation.php>`__.
Install the package by using Composer:
.. code-block:: bash
$ composer require mongodb/laravel-mongodb
In case your Laravel version does NOT autoload the packages, add the service
provider to ``config/app.php``:
.. code-block:: php
'providers' => [
// ...
MongoDB\Laravel\MongoDBServiceProvider::class,
],
Configuration
-------------
To configure a new MongoDB connection, add a new connection entry
to ``config/database.php``:
.. code-block:: php
'default' => env('DB_CONNECTION', 'mongodb'),
'connections' => [
'mongodb' => [
'driver' => 'mongodb',
'dsn' => env('DB_DSN'),
'database' => env('DB_DATABASE', 'homestead'),
],
// ...
],
The ``dsn`` key contains the connection string used to connect to your MongoDB
deployment. The format and available options are documented in the
:manual:`MongoDB documentation </reference/connection-string/>`.
Instead of using a connection string, you can also use the ``host`` and
``port`` configuration options to have the connection string created for you.
.. code-block:: php
'connections' => [
'mongodb' => [
'driver' => 'mongodb',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', 27017),
'database' => env('DB_DATABASE', 'homestead'),
'username' => env('DB_USERNAME', 'homestead'),
'password' => env('DB_PASSWORD', 'secret'),
'options' => [
'appname' => 'homestead',
],
],
],
The ``options`` key in the connection configuration corresponds to the
`uriOptions <https://www.php.net/manual/en/mongodb-driver-manager.construct.php#mongodb-driver-manager.construct-urioptions>`__
parameter.
You are ready to :ref:`create your first MongoDB model <laravel-eloquent-models>`.