updating to have db connection and index route

pull/1/head
Matt Huntington 5 years ago
parent e1f96ba7ed
commit b7d56d8ff1

@ -1,5 +1,7 @@
# Steps to Create and Deploy # Steps to Create and Deploy
## Initialize
- Make sure you have MAMP and Postgres installed and running - Make sure you have MAMP and Postgres installed and running
- Download comopser: https://getcomposer.org/composer-stable.phar - Download comopser: https://getcomposer.org/composer-stable.phar
- In Terminal, run: - In Terminal, run:
@ -16,3 +18,47 @@
- `cd` into your app's dir - `cd` into your app's dir
- run `php artisan serve` - run `php artisan serve`
- go to http://localhost:8000/ - go to http://localhost:8000/
## Connect to db
Connect to psql and
```
CREATE DATABASE contacts;
\c contacts
CREATE TABLE people (id SERIAL, name VARCHAR(16), age INT);
INSERT INTO people (name, age) VALUES ('matt', 40);
```
In `.env` file, adjust the following:
```
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
```
so it is:
```
DB_CONNECTION=pgsql
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=contacts
DB_USERNAME=matthuntington
DB_PASSWORD=
```
## Create routes
In `routes/api.php` add:
```php
Route::get('people', function () {
$users = DB::select('SELECT * FROM people');
return $users;
});
```

@ -17,3 +17,8 @@ use Illuminate\Support\Facades\Route;
Route::middleware('auth:api')->get('/user', function (Request $request) { Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user(); return $request->user();
}); });
Route::get('people', function () {
$users = DB::select('SELECT * FROM people');
return $users;
});

Loading…
Cancel
Save