Laravel 5.2使用Dingo(JWT)Api验证请求

时间:2017-01-18 04:49:46

标签: php laravel-5.2 jwt

Laravel 5.2请求验证在dingo(JWT)API中无效。

当我尝试调用控制器方法时,我会使用请求验证,这时它会返回打击错误。

错误 {"消息":" 500内部服务器错误"," status_code":500}

控制器

namespace App\Api\V1\Controllers;

  //use App\Http\Requests;
  use Illuminate\Http\Request;
  use App\Api\V1\Controllers\ApiController;
  use App\Http\Requests\StoreBlogPost;
  //use Request;
  use DB;

  class CommonController extends ApiController {

  public function getCabinet(StoreBlogPost $request) {
  $postData = $request->all();
  $floorkey = $postData ['FloorKey'];

  }

  }

请求

namespace App\Http\Requests;

  use App\Http\Requests\Request;

  class StoreBlogPost extends Request {

  /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
  public function authorize() {
  return False;
  }

  /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
  public function rules() {
  return [
  'FloorKey' => 'required',
  ];
  }

  public function response(array $error) {
  //Can't get json responce validation error in Controller 
  return response()->json(['error' => $error], 422);
  }

  }

1 个答案:

答案 0 :(得分:3)

将请求类App\Http\Requests\Request更改为Dingo\Api\Http\FormRequest