-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.php
39 lines (28 loc) · 1.12 KB
/
api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
use Illuminate\Http\Request;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::group(['middleware' => 'api'], function(){
Route::get('post/{id}/comments', function($id){
return \App\Post::findOrFail($id)->comments;
});
Route::post('post/{id}/comment',function($id, Request $request){
$user = \App\User::first();
return \App\Post::findOrFail($id)->comment($request->all(),$user);
});
Route::patch('post/{id}/comment/{comment_id}', function($id,$comment_id,Request $request){
return \App\Post::findOrFail($id)->updateComment($comment_id, $request->all());
});
Route::delete('post/{id}/comment/{comment_id}', function($id,$comment_id){
\App\Post::findOrFail($id)->deleteComment($comment_id);
return 'deleted';
});
});