Esempio n. 1
0
 public function configureApiRoutes(ConfigureApiRoutes $event)
 {
     Page::setFormatter(app()->make('flarum.formatter'));
     $event->get('/pages', 'pages.index', Controller\ListPagesController::class);
     $event->post('/pages', 'pages.create', Controller\CreatePageController::class);
     $event->get('/pages/{id}', 'pages.show', Controller\ShowPageController::class);
     $event->patch('/pages/{id}', 'pages.update', Controller\UpdatePageController::class);
     $event->delete('/pages/{id}', 'pages.delete', Controller\DeletePageController::class);
 }
 /**
  * @param CreatePage $command
  *
  * @return Page
  */
 public function handle(CreatePage $command)
 {
     $actor = $command->actor;
     $data = $command->data;
     $this->assertAdmin($actor);
     $page = Page::build(array_get($data, 'attributes.title'), array_get($data, 'attributes.slug'), array_get($data, 'attributes.content'), array_get($data, 'attributes.isHidden'));
     $this->validator->assertValid($page->getAttributes());
     $page->save();
     return $page;
 }
Esempio n. 3
0
 /**
  * Find a page by ID.
  *
  * @param int  $id
  * @param User $user
  *
  * @return Page
  *
  * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
  */
 public function findOrFail($id, User $user = null)
 {
     $query = Page::where('id', $id);
     return $this->scopeVisibleTo($query, $user)->firstOrFail();
 }