How to send send error message in json format to postman in laravel 5.4
//Controller
public function store(Request $request)
{
$validator = Validator::make($request->all(),[
'department_name' => 'required',
]);
if($validator->fails())
{
return $validator->errors()->all();
}
Department::create($request->all());
return Response::json(['message' => 'Added','status' => 201],201);
}
if ($validator->fails()) { return response()->json($validator->messages(), 200); }or a status other than 200 then in the client side test if status equal the new value then show errors !if ($validator->fails()) { return response()->json(['errors'=>$validator->errors()]); }!!