Skip to content

Commit f39e9f6

Browse files
author
Shashank Jain
committed
Fix: request arguments
1 parent 04c4840 commit f39e9f6

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/ApiController.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,14 @@ public function index()
164164
*
165165
* @return mixed
166166
*/
167-
public function show($id)
167+
public function show()
168168
{
169+
// We need to do this in order to support multiple parameter resource routes. For example,
170+
// if we map route /user/{user}/comments/{comment} to a controller, Laravel will pass `user`
171+
// as first argument and `comment` as last argument. So, id object that we want to fetch
172+
// is the last argument.
173+
$id = last(func_get_args());
174+
169175
$this->validate();
170176

171177
$results = $this->parseRequest()
@@ -210,10 +216,12 @@ public function store()
210216
return ApiResponse::make("Resource created successfully", [ "id" => $object->id ], $meta);
211217
}
212218

213-
public function update($id)
219+
public function update()
214220
{
215221
\DB::beginTransaction();
216222

223+
$id = last(func_get_args());
224+
217225
$this->validate();
218226

219227
// Get object for update
@@ -246,10 +254,12 @@ public function update($id)
246254
return ApiResponse::make("Resource updated successfully", [ "id" => $object->id ], $meta);
247255
}
248256

249-
public function destroy($id)
257+
public function destroy()
250258
{
251259
\DB::beginTransaction();
252260

261+
$id = last(func_get_args());
262+
253263
$this->validate();
254264

255265
// Get object for update

0 commit comments

Comments
 (0)