Sending the full page object to PageWasCreated

parent b68e58c8
......@@ -2,20 +2,41 @@
namespace Modules\Page\Events;
class PageWasCreated
use Modules\Media\Contracts\StoringMedia;
use Modules\Page\Entities\Page;
class PageWasCreated implements StoringMedia
{
/**
* @var array
*/
public $data;
/**
* @var int
* @var Page
*/
public $pageId;
public $page;
public function __construct($pageId, array $data)
public function __construct(Page $page, array $data)
{
$this->data = $data;
$this->pageId = $pageId;
$this->page = $page;
}
/**
* Return the entity
* @return \Illuminate\Database\Eloquent\Model
*/
public function getEntity()
{
return $this->page;
}
/**
* Return the ALL data sent
* @return array
*/
public function getSubmissionData()
{
return $this->data;
}
}
......@@ -60,7 +60,7 @@ class EloquentPageRepository extends EloquentBaseRepository implements PageRepos
event($event = new PageIsCreating($data));
$page = $this->model->create($event->getAttributes());
event(new PageWasCreated($page->id, $data));
event(new PageWasCreated($page, $data));
$page->setTags(array_get($data, 'tags', []));
......
......@@ -91,7 +91,7 @@ class EloquentPageRepositoryTest extends BasePageTest
]);
Event::assertDispatched(PageWasCreated::class, function ($e) use ($page) {
return $e->pageId === $page->id;
return $e->page->id === $page->id;
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment