why don't you use request() helper?
did you do dd($this->request) to see if it returns anything at all?
May 24, 2018
6
Level 1
$this->request->get() doesn't work inside FormRequest
The following form request is what I am attempting to create. It throws an invalid argument supplied for foreach error.
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SaveCatRequest extends FormRequest
{
/**
* 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()
{
$rules = [
'age' => 'required|string|in:cub,adolescent,adult',
'gender' => 'required|string|in:male,female',
'species' => 'required|numeric',
'pelt' => 'required|numeric',
'nose' => 'required|numeric',
'mane' => 'required|numeric',
'pawpad' => 'required|numeric',
'eye' => 'required|numeric'
];
$markings = [];
foreach ($this->request->get('m') as $m) {
$mark = explode(",", $m);
array_push($markings, (object) ['name' => $mark[0], 'color' => $mark[1], 'opacity' => floatval($mark[2])/100.0]);
foreach ($markings as $key => $val) {
$rules .= [
'name.*' => 'required|exists:markings',
'color.*' => 'required|exists:marking_colors,name',
'opacity' => 'required|between:0,100'
];
}
}
return $rules;
}
}
What am I doing wrong here?
Level 122
the form request is an extension of the request class
All you need is $this
1 like
Please or to participate in this conversation.