Im sorry if I am new to Laravel 5.2, but I get empty string in $errors even though if I use duplicate entry or purposely token mismatch it.
Here is the full code: http://laravel.io/bin/429WD - Routes.php http://laravel.io/bin/nQMNd - create.blade.php http://laravel.io/bin/JxK4v - TodoListController.php
TodoListController.php
public function store()
{
// define rules
$rules = array(
'title' => array('required', 'unique:todo_lists,name')
);
// pass input to rules (validator)
$validator = Validator::make(Input::all(), $rules);
// test if input is valid
if ($validator->fails()){
return Redirect::route('todos.create')->withError($validator, 'error');
}
$name = \Input::get('title');
$list = new TodoList();
$list -> name = $name;
$list -> save();
return Redirect::route('todos.index');
}
routes.php
Route::group(['middleware' => ['web']], function () {
Route::get('/db', function(){
$result = DB::table('todo_lists')->where('name', 'Your Name')->first();
return $result->name;
});
Route::get('/', 'TodoListController@index' );
Route::resource('todos', 'TodoListController' );
});
create.blade.php
{{ var_dump($errors) }}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community