Reputation: 2400
I am making a API, i want to check if the posted params (by curl) are equal to de resource params. If not i want to return a json with errors.
How do I get it done to check all route resource parameters?
Route::group(['prefix' => 'api' , 'middleware' => 'auth:api'], function () {
Route::resource('note' , 'NoteController');
});
Upvotes: 0
Views: 211
Reputation: 3538
You can handle the MethodNotAllowedHttpException
in Exception/Handler.php in method render
public function render($request, Exception $e)
{
// check if MethodNotAllowedHttpException exception type using status code 405 or instanceof
if ($e->getStatusCode() == 405) {
// custom your response. could be json with 404 or redirect to another page
return response()->json(['error' => true, 'message' => 'not found'], 404);
}
return parent::render($request, $e);
}
more explanation here
Upvotes: 1
Reputation: 2400
The answer is:
Routes.php
Route::put('note', 'NoteController@update');
Controller: $id = null and make a check id check
public function update(Request $request, $id = null){
if($id != null){
//do stuff
}
Upvotes: 0