mirror of
https://github.com/flarum/core.git
synced 2025-10-11 23:14:29 +02:00
Extract model validation into a trait
Also use Laravel’s ValidationException rather than our own custom one
This commit is contained in:
@@ -4,21 +4,27 @@ use DomainException;
|
||||
use Flarum\Core\Posts\Events\PostWasDeleted;
|
||||
use Flarum\Core\Model;
|
||||
use Flarum\Core\Support\Locked;
|
||||
use Flarum\Core\Exceptions\ValidationFailureException;
|
||||
use Flarum\Core\Support\EventGenerator;
|
||||
use Flarum\Core\Support\ValidatesBeforeSave;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class Post extends Model
|
||||
{
|
||||
use EventGenerator;
|
||||
use Locked;
|
||||
use ValidatesBeforeSave;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $table = 'posts';
|
||||
|
||||
/**
|
||||
* The validation rules for this model.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $rules = [
|
||||
protected $rules = [
|
||||
'discussion_id' => 'required|integer',
|
||||
'time' => 'required|date',
|
||||
'content' => 'required',
|
||||
@@ -30,11 +36,6 @@ class Post extends Model
|
||||
'hide_user_id' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $table = 'posts';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@@ -19,6 +19,8 @@ class PostsServiceProvider extends ServiceProvider
|
||||
new Extend\PostType('Flarum\Core\Posts\DiscussionRenamedPost')
|
||||
]);
|
||||
|
||||
Post::setValidator($this->app->make('validator'));
|
||||
|
||||
CommentPost::setFormatter($this->app->make('flarum.formatter'));
|
||||
|
||||
Post::allow('*', function ($post, $user, $action) {
|
||||
|
Reference in New Issue
Block a user