Last active
April 21, 2019 11:38
-
-
Save Titoratus/4b76c9581779f72ea84f91b0ac282985 to your computer and use it in GitHub Desktop.
[OctoberCMS] Валидация нескольких полей за один раз
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use \October\Rain\Exception\ValidationException; | |
class myModel extends Model | |
{ | |
public function beforeSave() | |
{ | |
// date_in, date_out - поля с датами! | |
$start = $this->date_in; | |
$end = $this->date_out; | |
$check = Db::table('mytable') | |
->whereBetween('myColumn', [$start, $end]) | |
->get(); | |
if ($check->count() > 0) | |
throw new ValidationException(['date_in' => 'My error message.']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment