你能在Laravel中扩展Command类吗?

时间:2015-04-02 09:29:08

标签: laravel-4 command

我目前正在处理使用Laravel 4的应用程序。我正在构建一个评论系统,并拥有执行创建,更新,删除的基本命令。

我接下来要做的是为附加评论的特定对象创建命令,例如Blog Post。

因此,如果我的命令文件被调用CreateCommentCommand,我想创建另一个名为CreatePostCommentCommand的命令。我希望这个新课程能够扩展CreateCommentCommand并将type硬编码。

因此对于CreateCommentCommand我有以下内容:

class CreateCommentCommand extends Command {

    public $commentable_type;
    public $commentable_id;
    public $comment;
    public $user_id;

    public function __construct($commentable_type = null,
                                $commentable_id = null,
                                $comment = null,
                                $user_id = null)
    {
        $this->commentable_type = $commentable_type;
        $this->commentable_id = $commentable_id;
        $this->comment = $comment;
        $this->user_id = $user_id;
    }

}

...对CreatePostCommentCommand我有:

class CreatePostCommentCommand extends CreateCommentCommand {

    public $commentable_type = 'post';

    public function __construct($commentable_id = null,
                                $comment = null,
                                $user_id = null)
    {
        $this->commentable_id = $commentable_id;
        $this->comment = $comment;
        $this->user_id = $user_id;
    }

}

对于处理程序,我CreatePostCommentCommandHandler扩展了CreateCommentCommandHandler。但是,我遇到的问题是当它遇到属于CreateCommentHandler的字段验证程序时,它会说$commentable_type未提供。

0 个答案:

没有答案
相关问题