i am new to laravel.Here i have a form where i have to fill up a name field and send it to controllers store() method for validation. Otherwise it will show custom error.But whenever i submit the form with or without input i am getting the following error.
Argument 1 passed to Illuminate\Validation\Factory::make() must be of the type array, string given, called in C:\xampp\htdocs\mylaravel\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 221 and defined
for experiment purpose i am catching the user input using the following format
$data = $request->input('name');
create.blade.php:
<h1>login form</h1>
@if($errors->has())
<div><span> Opps !! </span></br>
<ul>
@foreach ($errors->all() as $error)
<li> {{ $error }}</li>
@endforeach
</ul>
</div>
@endif
{!!Form::open(array('url'=>'user','method'=>'POST', 'files'=>true)) !!}
{!!Form::label('name','Your name')!!}
{!!Form::text('name')!!}
</br>
{!!Form::submit('submit')!!}
{!!Form::close()!!}
store() method in userController.php file:
public function store(Request $request)
{
//
$data = $request->input('name');
$rules = array(
'name' => 'unique:users,name|required|alpha_num'
);
// Create a new validator instance.
$validator = Validator::make($data, $rules);
if($validator->fails()){
$errors=$validator->messages();
return Redirect::route('user.create')->withErrors($validator);
}else{
return Redirect::route('user.index');
}
}
}