(im new with laravel)
postman api test error like this all the time
"status": false,
"message": "Method Illuminate\Validation\Validator::false does not exist."
the function for register a new user for test
<?php
namespace AppHttpControllersApi;
use AppModelsUser;
use IlluminateHttpRequest;
use IlluminateSupportCarbon;
use AppHttpControllersController;
use IlluminateSupportFacadesِAuth;
use IlluminateSupportFacadesHash;
use IlluminateSupportFacadesValidator;
class UserController extends Controller
{
/**
* Create User
* @param Request $request
* @return Response
*/
public function createUser(Request $request)
{
try {
$validateUser = Validator::make($request->all(),
[
'name'=> 'required',
'email' => 'required|email|unique:users,email',
'password' => 'required'
]);
if($validateUser->false()){
return response()->json([
'status' => false,
'message' => 'validation error',
'errors' => $validateUser->errors()
], 401);
}
$user = User::ceate([
'name' => $request->name,
'message' => $request->email,
'password' => $request->password
]);
return response()->json([
'status' => true,
'message' => 'User Created Succssfully',
'token' => $userInfo
], 200);
} catch(Throwable $th){
return response()->json([
'status' => false,
'message' => $th->getMessage()
], 401);
}
}
}
can any one help me i use (use Validator;) and still get same error !!
2
Answers
Use
$validateUser->fails()
instead of$validateUser->false()
I believe you are looking for fails, not false, from the Laravel documentation:
so your code is going to be:
See Laravel documentation for more information.