jeudi 20 juillet 2017

laravel: vaidation vs migration schema rules

i have a migration with the following:

Schema::create('ingredients', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name',10)->unique()->nullable(false);
    $table->timestamps();
});

If you note i want the string not to exceed 10 characters

In my controller i have:

$this->validate($request, [
    'name' => 'bail|required|unique:ingredients|max:200',
]);

In the controller i have mentioned the max characters to be 200.

So when i fill the form with more than 10 characters and less than 200 characters it get stored in the database. How is this possible.

Will laravel not check the integrity between then migration files schema rules and the validation rules.

Also another thing i noted is: If i remove the validation rules from the controller and submit the form, still it does not check for the number of character w.r.t 10. It creates a new database record. Where as it checks for the unique record even i dont use any validation rules.

why unique is checked is checked irrespective of mentioning in the validation rules.

Also the maximum number of characted (10) in the migration file has no significance. because with or without validation rules i can input name with more than 10 characters.

Where as if i have my validation rule saying max:2 then it shows the form errors while submitting.

So its bit confusing which work from migration file irrespective of the validation rules and which does not work at all even its mentioned in the migration table.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2uFMQPM
via IFTTT

Aucun commentaire:

Enregistrer un commentaire