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
I'll be working alongside [this tutorial](https://www.toptal.com/laravel/restful-laravel-api-tutorial) for building the API
5
+
6
+
**Step 1:** Create project with [this handy script](https://gist.github.com/connor11528/fcfbdb63bc9633a54f40f0a66e3d3f2e)
7
+
8
+
I also wrote [this Medium article](https://medium.com/@connorleech/build-an-online-forum-with-laravel-initial-setup-and-seeding-part-1-a53138d1fffc) that goes through installing and configuring a MySQL database for a Laravel 5 application. I find myself refering back to it regularly.
9
+
10
+
**Step 2:** Configure database and make models
11
+
12
+
If you don't have MySQL installed on Mac may the force be with you. It comes preinstalled and there's MAMP but getting your machine set up to run SQL to MySQL from the terminal can be tricky.
13
+
14
+
My setup is to run:
15
+
16
+
```
17
+
$ mysql -uroot -p
18
+
> create database MY_APP_NAME;
19
+
$ php artisan make:model Article -m
20
+
```
21
+
22
+
The `;` is required in order to end all SQL statements.
23
+
24
+
Add a **title** and **body** string columns to the articles database and run the migrations:
25
+
26
+
```
27
+
$ php artisan migrate
28
+
```
29
+
30
+
If you get an error saying cannot connect to homestead, even after you updated your .env to not point to homestead anymore clear the config and try again.
31
+
32
+
To clear config in Laravel:
33
+
34
+
```
35
+
$ php artisan config:clear
36
+
```
37
+
38
+
Make the models fillable (Laravel will protect them by default). Add this line to **app/Article.php**:
39
+
40
+
```
41
+
protected $fillable = ['title', 'body'];
42
+
```
43
+
44
+
Fillable will allow reads and writes to those database columns. You could also set a guarded property to an empty array:
45
+
46
+
```
47
+
$guarded = []
48
+
```
49
+
50
+
Which for our purposes will do the same thing. To learn more about this you can check the Eloquent docs on [Mass Assignment](https://laravel.com/docs/5.5/eloquent#mass-assignment).
0 commit comments