Skip to content

Commit a472c77

Browse files
committed
expnaded but still some errors
1 parent 0a1695f commit a472c77

File tree

8 files changed

+27
-13
lines changed

8 files changed

+27
-13
lines changed

app/Http/Controllers/AuthController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function postLogin(Request $request)
4747
}
4848

4949
// login is successful. fire an event to send a mail to user with ip addr
50-
event((new UserLoggedIn($request)));
50+
event((new UserLoggedIn($request)));
5151

5252

5353
return response()->json(compact('token'));

database/factories/ModelFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
return [
2323
'name' => 'Jake',
2424
'email' => '[email protected]',
25-
'password' => app('hash')->make('secret'),
25+
'password' => app('hash')->make('delfino'),
2626
];
2727
});

database/migrations/2019_04_02_123120_create_posts_table.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ class CreatePostsTable extends Migration
99
*
1010
* @return void
1111
*/
12-
public function up()
13-
{
14-
Schema::create('posts', function (Blueprint $table) {
15-
$table->increments('id');
16-
$table->timestamps();
12+
public function up()
13+
{
14+
Schema::create('posts', function (Blueprint $table) {
15+
$table->increments('id');
16+
$table->timestamps();
17+
});
1718
}
1819
/**
1920
* Reverse the migrations.

database/seeds/PostsTableSeede.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
use App\Post;
43
use Illuminate\Database\Seeder;
54

65
class PostsTableSeeder extends Seeder
@@ -12,6 +11,6 @@ class PostsTableSeeder extends Seeder
1211
*/
1312
public function run()
1413
{
15-
factory(Post::class, 20)->create(); // whenever this is called created 20 records for posts based on rules defined in model factory for posts
14+
factory(App\Post::class, 20)->create(); // whenever this is called created 20 records for posts based on rules defined in model factory for posts
1615
}
1716
}

database/seeds/UsersTableSeeder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
use App\User;
2+
33
use Illuminate\Database\Seeder;
44
class UsersTableSeeder extends Seeder
55
{
@@ -10,7 +10,7 @@ class UsersTableSeeder extends Seeder
1010
*/
1111
public function run()
1212
{
13-
factory(User::class, 1)->create();
13+
factory(App\User::class, 1)->create();
1414

1515
}
1616
}
794 KB
Loading

readme.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ php artisan migrate
148148
This will migrate schema to database according to what is present in migration file. Now your database will have **posts table**.
149149
This is how Eloquent makes it so easy to create tables, share this schema with the team and use its simple functions to generate complex sql queries.
150150

151-
**8) Test the API**
151+
**8) Fake data to use for the test of the API**
152152

153153
Now the issue how we test the API if we do not have any data to
154154
test actually.
@@ -162,3 +162,17 @@ Now we need the a **seeder class** to call this factory to start creating object
162162
Will ask it to create 20 objects whenever it is called. Inside
163163
`database/seeds/DatabaseSeeder.php` call `PostsTableSeeder`.
164164
Now we will run `php artisan db:seed` command to seed the database. Which will call `run()` in `DatabaseSeeder.php` and seed all listed seeders. We now have 20 dummy records inside posts table.
165+
166+
Example:
167+
![seeds](doc/Screenshot 2019-04-03 at 23.57.20.png)
168+
169+
**9) API end points**
170+
171+
If we go to `routes/web.php` here is we define our endpoints/routes. For example if one wants to get all posts one will set an endpoint with `url posts/all`.
172+
See the file. One used `Post::all()` (in a callback function)
173+
which is **Eloquent** way to fetch all the results for a
174+
model which has also been discussed earlier.
175+
Now if one hit the endpoint through **Postman** or visit in browser
176+
`localhost/posts/all` one should see 20 blog posts in json.
177+
178+
Example:

routes/web.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
{
4141
$router->get('/test', function() {
4242
return response()->json([
43-
'message' => 'Hello World!',
43+
'message' => 'Yeah you can access!',
4444
]);
4545
});
4646
});

0 commit comments

Comments
 (0)