Answer the question
In order to leave comments, you need to log in
How to properly validate data in Laravel?
API has Route
Route::get('/hint/{hintId}', '[email protected]');
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class GetHint extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'hintId' => 'required|integer',
];
}
}
public function show(Request $request)
{
$hint = Hint::where('id', $request->hintId)->first();
return new HintResource($hint);
}
{
"message": "The given data was invalid.",
"errors": {
"hintId": [
"The hint id field is required."
]
}
}
Answer the question
In order to leave comments, you need to log in
Try using GetHint Request . That is like this:
use App\Http\Requests\GetHint as GetHintRequest;
......
public function show(GetHintRequest $request)
{
$hint = Hint::where('id', $request->hintId)->first();
return new HintResource($hint);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question