Jan 30, 2019
0
Level 1
Laravel/ Lumen formRequest throwing error on submitting all valid values
I'm using this library for formRequest feature in my Lumen application. I had installed and configured as mentioned in docs but there seems to be somewhere I might be missing or issue in library. Following is my sample code
Validation Class: <?php namespace App\Http\Requests;
use Pearl\RequestValidate\RequestAbstract;
use Illuminate\Validation\Rule;
use Illuminate\Http\Response;
class CommentFormRequest extends RequestAbstract
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required'
'title' => 'required|max:255',
'body' => 'required',
];
}
/**
* Get custom messages for validator errors.
*
* @return array
*/
public function messages()
{
return [
//
];
}
}
Controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests\CommentFormRequest;
class CommentController extends Controller
{
public function add(CommentFormRequest $request)
{
$request->validated();
return response()->json(['Success']);
}
}
When I submit invalid data from postman, valid errors are thrown but when I submit valid data without missing any form field then following error is showing.
(1/1) BadMethodCallException
Method App\Http\Requests\CommentFormRequest::validated does not exist.
Above error totally making me confusion because if validated method is not found then how its throwing error for invalid data? I had tried to debug the issue but as I'm new to Lumen nothing I'm able to figure it out to fix this issue.
Please or to participate in this conversation.