**已关闭。**此问题为not reproducible or was caused by typos。目前不接受答复。
此问题是由打印错误或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
13小时前关闭
Improve this question
(im新的laravel) Postman API测试错误这样的所有时间
"status": false,
"message": "Method Illuminate\\Validation\\Validator::false does not exist."
注册新用户进行测试功能
<?php
namespace App\Http\Controllers\Api;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\ِAuth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
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);
}
}
}
可以任何一个帮助我我使用(使用验证器;)并且仍然得到相同的错误!!
2条答案
按热度按时间yqkkidmi1#
使用
$validateUser->fails()
代替$validateUser->false()
n9vozmp42#
我相信你正在寻找失败,而不是错误,从Laravel文档:
所以你的代码将是:
请参阅Laravel文档以获取更多信息。