I had some original code that shows like below with form validation and saving process in MySQL Database.
Original Code
public function store(Request $request)
{
$v = \Validator::make($request->all(), [
'Category' => 'required|unique:tblcategory|max:25|min:5'
]);
if ($v->fails()) {
return \Redirect::back()
->withErrors($v)
->withInput();
}
...
//code to save the record in database is here....
...
}
Then I followed this article and modified the above function and now it looks like below.
public function store(CategoryRequest $request)
{
...
//code to save the record in database is here....
...
}
and below is the Request class
class CategoryRequest extends Request
{
protected $redirect = \Redirect::back()->withErrors($v)->withInput();
public function authorize()
{
return false;
}
public function rules()
{
return [
'Category' => 'required|unique:tblcategory|max:25|min:5'
];
}
}
Error Details
syntax error, unexpected '(', expecting ',' or ';'
This error is coming at below line.
protected $redirect = \Redirect::back()->withErrors($v)->withInput();
Am I missing something ?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire