Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0d47c03

Browse files
Updated database configuration
1 parent bc39ae6 commit 0d47c03

File tree

3 files changed

+33
-65
lines changed

3 files changed

+33
-65
lines changed

‎bootstrap/autoload.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@
3232
if (file_exists($compiledPath)) {
3333
require $compiledPath;
3434
}
35+
36+
require __DIR__.'/helpers.php';

‎bootstrap/helpers.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
function get_db_config()
4+
{
5+
if (getenv('IS_IN_HEROKU')) {
6+
$url = parse_url(getenv("DATABASE_URL"));
7+
8+
return $db_config = [
9+
'connetion' => 'pgsql',
10+
'host' => $url["host"],
11+
'database' => substr($url["path"], 1),
12+
'username' => $url["user"],
13+
'password' => $url["pass"],
14+
];
15+
} else {
16+
return $db_config = [
17+
'connetion' => env('DB_CONNECTION', 'mysql'),
18+
'host' => env('DB_HOST', 'localhost'),
19+
'database' => env('DB_DATABASE', 'forge'),
20+
'username' => env('DB_USERNAME', 'forge'),
21+
'password' => env('DB_PASSWORD', ''),
22+
];
23+
}
24+
}

‎config/database.php

Lines changed: 7 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,12 @@
11
<?php
22

3-
return [
3+
$db_config = get_db_config();
44

5-
/*
6-
|--------------------------------------------------------------------------
7-
| PDO Fetch Style
8-
|--------------------------------------------------------------------------
9-
|
10-
| By default, database results will be returned as instances of the PHP
11-
| stdClass object; however, you may desire to retrieve records in an
12-
| array format for simplicity. Here you can tweak the fetch style.
13-
|
14-
*/
5+
return [
156

167
'fetch' => PDO::FETCH_CLASS,
178

18-
/*
19-
|--------------------------------------------------------------------------
20-
| Default Database Connection Name
21-
|--------------------------------------------------------------------------
22-
|
23-
| Here you may specify which of the database connections below you wish
24-
| to use as your default connection for all database work. Of course
25-
| you may use many connections at once using the Database library.
26-
|
27-
*/
28-
29-
'default' => env('DB_CONNECTION', 'mysql'),
30-
31-
/*
32-
|--------------------------------------------------------------------------
33-
| Database Connections
34-
|--------------------------------------------------------------------------
35-
|
36-
| Here are each of the database connections setup for your application.
37-
| Of course, examples of configuring each database platform that is
38-
| supported by Laravel is shown below to make development simple.
39-
|
40-
|
41-
| All database work in Laravel is done through the PHP PDO facilities
42-
| so make sure you have the driver for your particular database of
43-
| choice installed on your machine before you begin development.
44-
|
45-
*/
9+
'default' => $db_config['connetion'],
4610

4711
'connections' => [
4812

@@ -66,10 +30,10 @@
6630

6731
'pgsql' => [
6832
'driver' => 'pgsql',
69-
'host' => env('DB_HOST', 'localhost'),
70-
'database' => env('DB_DATABASE', 'forge'),
71-
'username' => env('DB_USERNAME', 'forge'),
72-
'password' => env('DB_PASSWORD', ''),
33+
'host' => $db_config['host'],
34+
'database' => $db_config['database'],
35+
'username' => $db_config['username'],
36+
'password' => $db_config['password'],
7337
'charset' => 'utf8',
7438
'prefix' => '',
7539
'schema' => 'public',
@@ -87,30 +51,8 @@
8751

8852
],
8953

90-
/*
91-
|--------------------------------------------------------------------------
92-
| Migration Repository Table
93-
|--------------------------------------------------------------------------
94-
|
95-
| This table keeps track of all the migrations that have already run for
96-
| your application. Using this information, we can determine which of
97-
| the migrations on disk haven't actually been run in the database.
98-
|
99-
*/
100-
10154
'migrations' => 'migrations',
10255

103-
/*
104-
|--------------------------------------------------------------------------
105-
| Redis Databases
106-
|--------------------------------------------------------------------------
107-
|
108-
| Redis is an open source, fast, and advanced key-value store that also
109-
| provides a richer set of commands than a typical key-value systems
110-
| such as APC or Memcached. Laravel makes it easy to dig right in.
111-
|
112-
*/
113-
11456
'redis' => [
11557

11658
'cluster' => false,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /