Reputation: 106
im trying to validate a set of fields and i get this error, i tried google,laracast but to no help Here is my controller
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Validator;
public function add_banner_submit()
{
$data= Input::except(array('_token'));
$rule = array(
'uname'=>'required',
'image'=>'image|mimes:jpeg,png,jpg,gif,svg|required',
'url'=>'required',
);
$validator = Validator::make($rule,$data);
if ($validator->fails()) {
return view('siteadmin.add_banner');
} else {
$inputs=Input::all();
$entry=array(
'uname'=>Input::get('uname'),
'image'=>Input::get('image'),
'url'=>Input::get('url')
);
Banner::add_banner_submit($entry);
echo"success";
return view('siteadmin.add_banner');
}
}
what could be the issue,? Any help is appreciated
Upvotes: 2
Views: 47
Reputation: 106
haha actually the Solution was simple,i just had to interchange
$validator = Validator::make($data,$rule);
to this then it worked ,the validator was referencing to the rule first before data so i got the error
Upvotes: 1
Reputation: 9853
Change this line-
$validator = Validator::make($rule,$data);
To this-
$validator = Validator::make($data, $rule);
Upvotes: 1