File tree Expand file tree Collapse file tree 2 files changed +10
-9
lines changed
Expand file tree Collapse file tree 2 files changed +10
-9
lines changed Original file line number Diff line number Diff line change 55use App \Comments ;
66use App \Post ;
77use Illuminate \Http \Request ;
8+ use App \Http \Resources \Comments as CommentResource ;
89
910class CommentsController extends Controller
1011{
@@ -26,8 +27,8 @@ public function index(Post $post)
2627 */
2728 public function store (Post $ post ,Request $ request )
2829 {
29- $ post ->comments ()->create ($ request ->all ());
30- return response (' created ' , ' 200 ' );
30+ $ comment = $ post ->comments ()->create ($ request ->all ());
31+ return response ()-> json ( new CommentResource ( $ comment ), 200 );
3132 }
3233
3334 /**
Original file line number Diff line number Diff line change @@ -17,12 +17,12 @@ class Comments extends JsonResource
1717 */
1818 public function toArray ($ request )
1919 {
20- return [
21- 'id ' => $ this ->id ,
22- 'body ' => $ this ->body ,
23- 'user ' => new UserResource ($ this ->user ),
24- 'created_at ' => $ this ->created_at ->diffForHumans (),
25- 'updated_at ' => $ this ->updated_at ->diffForHumans (),
26- ];
20+ return [
21+ 'id ' => $ this ->id ,
22+ 'body ' => $ this ->body ,
23+ 'user ' => new UserResource ($ this ->user ),
24+ 'created_at ' => $ this ->created_at ->diffForHumans (),
25+ 'updated_at ' => $ this ->updated_at ->diffForHumans (),
26+ ];
2727 }
2828}
You can’t perform that action at this time.
0 commit comments