Laravel 5.4 - 验证无效

时间:2017-04-19 04:58:33

标签: laravel-5 laravel-validation

我做错了验证

<?php

namespace App\Http\Controllers\Auth;

use Validator;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class SignupController extends Controller
{
  public function postSignup(Request $request)
  {
      if($this->validate($request, [
          'first_name' => 'required|max:255'
      ])){
          echo json_encode(array('TRUE'));
      }else{
          echo json_encode(array('FALSE'));
      }
  }
}

请求数据是正确的......

但验证器总是返回null ...而返回的json是FALSE

1 个答案:

答案 0 :(得分:0)

validate不返回true或false。它失败时抛出异常,如果成功则不返回任何内容。

谢谢你@apokryfos