Add validation for query
This commit is contained in:
parent
b4c44f5a14
commit
ae59f826e9
@ -4,6 +4,8 @@
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
@ -16,6 +18,15 @@ public function index()
|
||||
// GET /user/{id}
|
||||
public function show(string $id)
|
||||
{
|
||||
// FIXME: is there more shorter
|
||||
// validation solution
|
||||
$v = Validator::make(["id" => $id], [
|
||||
"id" => 'integer'
|
||||
]);
|
||||
|
||||
if ($v->fails())
|
||||
throw new BadRequestException();
|
||||
|
||||
$user = User::query()->findOrFail($id);
|
||||
|
||||
return response($user);
|
||||
|
Loading…
Reference in New Issue
Block a user