From b7d56d8ff1ea76632b2e21a2082834ca74600662 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Thu, 8 Oct 2020 15:16:34 -0400 Subject: [PATCH] updating to have db connection and index route --- README.md | 48 +++++++++++++++++++++++++++++++++++++++++++++++- routes/api.php | 5 +++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 064554f..a8abd80 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ # Steps to Create and Deploy +## Initialize + - Make sure you have MAMP and Postgres installed and running - Download comopser: https://getcomposer.org/composer-stable.phar -- In Terminal, run: +- In Terminal, run: - `mv ~/Downloads/composer-stable.phar /usr/local/bin/composer` - `chmod 755 /usr/local/bin/composer` @@ -16,3 +18,47 @@ - `cd` into your app's dir - run `php artisan serve` - 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; +}); +``` diff --git a/routes/api.php b/routes/api.php index bcb8b18..d39b884 100644 --- a/routes/api.php +++ b/routes/api.php @@ -17,3 +17,8 @@ use Illuminate\Support\Facades\Route; Route::middleware('auth:api')->get('/user', function (Request $request) { return $request->user(); }); + +Route::get('people', function () { + $users = DB::select('SELECT * FROM people'); + return $users; +});