2

My Laravel Framework is 5.4.19

I have followed the tutorial: http://www.easylaravelbook.com/blog/2015/08/17/creating-and-validating-a-laravel-5-form-the-definitive-guide/

and created form request file tours2_create_tableRequest.php:

<?php namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; class tours2_create_tableRequest extends FormRequest { public function authorize() { return true; } public function rules() { return [ 'doc_fullnumber' => 'unique:tourists' ]; } 

}

(it tests if "doc_fullnumber" from request has no duplicates in 'tourists" model)

I have added this code to the form blade.php file:

 @if($errors->count() > 0 ) <div> @foreach ($errors->all() as $error) {{ $error }} @endforeach </div> @endif 

it seems to me that validation works fine (it redirects the user back to create form page when "doc_fullnumber" is not unique), but it doesn't pass $errors variable.

I've browsed Stackoverflow and found several topics with the same problem. They suggest to wrap all my routes (in web.php) in:

Route::group(['middleware' => ['web']], function () { }); 

I've done it, but it doesn't help...

here is the form page, actually (temporary): http://f832ee57.ngrok.io/tours_2/create (the "doc_fullnumber" field is the last one. You can add "2001" there to check validation).

my project on git: https://github.com/Sergey1983/first

Appreciate any help!

2
  • In your validation add table name . I had same issue got mine fixed with it unique:table_name.tourists Commented Jun 6, 2017 at 16:35
  • Thanx, Paudel. But 'tourists' is actually the table name. Commented Jun 6, 2017 at 22:01

1 Answer 1

1

To make the unique rule work, you need to have `'doc_fullnumber' field in DB or you need to specify a custom name field:

'doc_fullnumber' => 'unique:tourists,custom_fullnumber_field' 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.