Skip to content

Commit 58d1127

Browse files
committed
Small fixes in API
1 parent d3f6194 commit 58d1127

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

app/Api/V1/Controllers/BookController.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ class BookController extends Controller
1919

2020
public function index() {
2121
$currentUser = JWTAuth::parseToken()->authenticate();
22-
return $currentUser
23-
->books()
24-
->orderBy('created_at', 'DESC')
25-
->get()
22+
// return $currentUser
23+
// ->books()
24+
// ->orderBy('created_at', 'DESC')
25+
// ->get()
26+
// ->toArray();
27+
return Book::all()
2628
->toArray();
29+
30+
2731
}
2832

2933
public function store(Request $request) {
@@ -48,7 +52,8 @@ public function show($id)
4852
{
4953
$currentUser = JWTAuth::parseToken()->authenticate();
5054

51-
$book = $currentUser->books()->find($id);
55+
// $book = $currentUser->books()->find($id);
56+
$book = Book::all()->find($id);
5257

5358
if(!$book)
5459
throw new NotFoundHttpException;
@@ -65,7 +70,8 @@ public function update(Request $request, $id)
6570
{
6671
$currentUser = JWTAuth::parseToken()->authenticate();
6772

68-
$book = $currentUser->books()->find($id);
73+
// $book = $currentUser->books()->find($id);
74+
$book = Book::all()->find($id);
6975
if(!$book)
7076
throw new NotFoundHttpException;
7177

@@ -86,7 +92,8 @@ public function destroy($id)
8692
{
8793
$currentUser = JWTAuth::parseToken()->authenticate();
8894

89-
$book = $currentUser->books()->find($id);
95+
// $book = $currentUser->books()->find($id);
96+
$book = Book::all()->find($id);
9097

9198
if(!$book)
9299
throw new NotFoundHttpException;

app/Http/api_routes.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
return \App\User::all();
2020
});
2121

22+
23+
$api->get('freebooks',function() {
24+
return \App\Book::all();
25+
});
26+
2227
$api->group(['middleware' => 'api.auth'], function ($api) {
2328
$api->get('books', 'App\Api\V1\Controllers\BookController@index');
2429
$api->get('books/{id}', 'App\Api\V1\Controllers\BookController@show');
@@ -31,5 +36,7 @@
3136
/// this line can replace all of the "book methods from above"
3237
/// $api->resource('books', 'App\Api\V1\Controllers\BookController');
3338

39+
// Token
40+
// eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjE2LCJpc3MiOiJodHRwOlwvXC9kZXYuYWRtaW5cL2FwaVwvYXV0aFwvbG9naW4iLCJpYXQiOjE0NjQzNDI5ODIsImV4cCI6MTQ2NDM0NjU4MiwibmJmIjoxNDY0MzQyOTgyLCJqdGkiOiIyMWM5YjhhODEzZmM0Y2ViZGU5MDNjN2Q4ZDhjOGNlZiJ9.pjX8kCJ0PnuKmjEaXI9K3IHs9DwTmaKBoN1a5sDzeos
3441

3542
});

resources/views/books/index.blade.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
<th>Title</th>
1717
<th>Author Name</th>
1818
<th>Page Count</th>
19+
<th>User ID</th>
20+
1921
<th></th>
2022
</tr>
2123
</thead>
@@ -26,6 +28,7 @@
2628
<td>{{ $book->title }}</td>
2729
<td>{{ $book->author_name }}</td>
2830
<td>{{ $book->pages_count }}</td>
31+
<td>{{ $book->user_id}}</td>
2932
<td>
3033
<a href="/user/{{ $book->id }}/edit" class="btn btn-info pull-left" style="margin-right: 3px;">Edit</a>
3134

resources/views/users/index.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
<thead>
1515
<tr>
16+
<th>ID</th>
1617
<th>Name</th>
1718
<th>Email</th>
1819
<th>Date/Time Added</th>
@@ -23,6 +24,7 @@
2324
<tbody>
2425
@foreach ($users as $user)
2526
<tr>
27+
<td>{{ $user->id }}</td>
2628
<td>{{ $user->name }}</td>
2729
<td>{{ $user->email }}</td>
2830
<td>{{ $user->created_at->format('F d, Y h:ia') }}</td>

0 commit comments

Comments
 (0)