The validation in api doesn't work in postman for my laravel project

FatSam8

I try to put a validation in a single-action controller and test the API in postman, but it doesn't show anything.

namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class BookableAvailabilityController extends Controller
{

public function __invoke(Request $request)
{
       $data = $request->validate([
         'from' => 'required|date_format:Y-m-d|after_or_equal:now',
         'to' => 'required|date_format:Y-m-d|after_or_equal:from',
]); 
 }
 }

and I defined the route in API file:

Route::get('bookables/{bookable}/availability', 'Api\BookableAvailabilityController')

The route is right as it is shown in the route:list

enter image description here

But the postman show the code 200 says everything is OK

enter image description here

iCoders

$request->validate method, if validation fails, an exception will be thrown and the proper error response will automatically be sent back to the user. In the case of a traditional HTTP request, a redirect response will be generated, while a JSON response will be sent for AJAX requests.

You can use Validator function .so that you can pass custom response

$validator = Validator::make($request->all(), [ 
      'from' => 'required|date_format:Y-m-d|after_or_equal:now',
         'to' => 'required|date_format:Y-m-d|after_or_equal:from',
  ]);

  if ($validator->fails()) {
    return response()->json($validator->errors(), 422);
  }

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

My ShaderProgram doesn't work

分類Dev

Why doesn't zurb foundation off-canvas work in my project?

分類Dev

Laravel JSON validation failed with postman

分類Dev

Add Function of my MutableList doesn't work

分類Dev

Redirection rule doesn't work in my .htaccess

分類Dev

My Python TeleBot Calculator doesn't work

分類Dev

Why my xpath doesn't work

分類Dev

Why doesn't my SetLength work?

分類Dev

my program doesn't work on an special system

分類Dev

Iptables: why my redirection doesn't work?

分類Dev

Why doesn't my SUMIF formula work?

分類Dev

Why doesn't my InStr Work?

分類Dev

My second endpoint doesn't work for node-js API, why?

分類Dev

Count in update query doesn't work in Laravel

分類Dev

Validation for input box, use Jquery focusin function doesn't work

分類Dev

HTML/JavaScript Inline Validation doesn't work fully

分類Dev

Geocode in Twitter API doesn't work

分類Dev

gmaps.js Api doesn't work

分類Dev

Why does my first snippit work, but my second doesn't?

分類Dev

Api work with Postman but not in android application

分類Dev

Why doesn't auto complete work in my shell?

分類Dev

Contains method doesn't seem to work with a point inside my polygon

分類Dev

My spawning system doesn't work and I dont know why

分類Dev

Why doesn't my implementation of linked list work?

分類Dev

Why my args[1] doesn't work in this case in discord

分類Dev

Why my router navigate function doesn't work in angular 8?

分類Dev

why does my window doesn't work for on_draw?

分類Dev

Why my simple filter in Jersey doesn't work?

分類Dev

Why doesn't anything in my if-else work?

Related 関連記事

ホットタグ

アーカイブ