I have an input field that I am adding dynamically with jQuery, it is the input field for video links, that a user can add as many times as he wants to, and I need to check if the url is valid for all the fields if something is written in them, I also need to leave it as an optional field. I was trying to do it by following this example but that is obviously not working for me:
This is my form field:
{!! Form::text('external_media[]', null,['class' => 'form-control col-lg-10 external-media-input']) !!}
And in my controller store function I was trying to validate it like this:
$this->validate($request->all(), [
'external_media.*' => 'present|active_url',
]);
When I am sending data from the create form, $request->all() looks like this:
array:11 [▼
"_token" => "JQXZjFEs3ETgVqh2izcmJx1h3sGryFvDkzGGtVAd"
"external_media" => array:3 [▶]
"category" => "1"
"type" => "0"
"title" => "sdbvsdb"
]
But I get the error:
FatalThrowableError in ValidatesRequests.php line 49:
Type error: Argument 1 passed to App\Http\Controllers\Controller::validate() must be an instance of Illuminate\Http\Request, array given, called in /home/vagrant/Projects/myProject/app/Http/Controllers/Admin/Articles/ArticlesController.php on line 66
I have also tried with making the validation with rules in a requests file like this:
$rules = [
'title' => 'required',
'text' => 'required',
//'image' => 'required|image|max:20000',
];
foreach($this->request->get('external_media') as $val)
{
$rules[$val] = 'present|active_url';
}
return $rules;
But then when I have a blank field for external_media, I get this error:
ErrorException in helpers.php line 531:
htmlentities() expects parameter 1 to be string, array given (View: /home/vagrant/Projects/iCoop5.2/resources/views/admin/articles/create.blade.php)