Bypass that class altogether. You should instead extend Validator which won't tie you to the behavior of the FormRequest class. I've included a recent example of something I've been working on that might help. Note it uses the validator class I talked about. Also I created an API controller which this one extends that adds a few helper methods. I've included those below as well:
// API Controller
/**
* Handles an error response formatting it according to our spec.
*
* @param array $error
* @param array $headers
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function respondWithError($error, $headers = [])
{
return response()->json(['errors' => $error])->setStatusCode($this->getStatusCode());
}
/**
* @param Model $item
* @param TransformerAbstract $transformer
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function respondWithItem(Model $item, TransformerAbstract $transformer)
{
$resource = new Item($item, $transformer);
return response()->json($this->manager->createData($resource)->toArray())->setStatusCode($this->getStatusCode());
}
// ModelController
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$data = $request->input('data');
$validator = $this->validator($data);
if ($validator->fails()) {
$this->setStatusCode(422);
return $this->respondWithError($validator->errors());
}
$account = new Account();
$account->name = $data['name'];
$account->subdomain = $data['subdomain'];
$account->save();
$this->setStatusCode(201);
return $this->respondWithItem($account, new AccountTransformer);
}
private function validator($data)
{
return Validator::make($data, [
'subdomain' => 'required|unique:accounts|max:50',
'name' => 'required',
'address' => 'required|array|min:1',
'phone' => 'required|array|min:1'
]);
}