mirror of
https://github.com/flarum/core.git
synced 2025-07-25 18:51:40 +02:00
Add model validation back in
This commit is contained in:
@@ -38,6 +38,20 @@ class Model extends Eloquent
|
||||
*/
|
||||
protected static $validator;
|
||||
|
||||
/**
|
||||
* Validate the model on save.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::saving(function ($model) {
|
||||
$model->assertValid();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the relationship with the forum.
|
||||
*
|
||||
@@ -87,7 +101,8 @@ class Model extends Eloquent
|
||||
*/
|
||||
public function assertValid()
|
||||
{
|
||||
if ($this->makeValidator()->fails()) {
|
||||
$validation = $this->makeValidator();
|
||||
if ($validation->fails()) {
|
||||
throw (new ValidationFailureException)
|
||||
->setErrors($validation->errors())
|
||||
->setInput($validation->getData());
|
||||
@@ -103,7 +118,7 @@ class Model extends Eloquent
|
||||
{
|
||||
$rules = $this->expandUniqueRules(static::$rules);
|
||||
|
||||
return $this->validator->make($this->attributes, $rules, static::$messages);
|
||||
return static::$validator->make($this->attributes, $rules);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -21,7 +21,7 @@ class User extends Model
|
||||
* @var array
|
||||
*/
|
||||
public static $rules = [
|
||||
'username' => 'required|username|unique',
|
||||
'username' => 'required|unique',
|
||||
'email' => 'required|email|unique',
|
||||
'password' => 'required',
|
||||
'join_time' => 'date',
|
||||
|
Reference in New Issue
Block a user