/** * @test */ public function it_allows_choice_no_category() { $this->actingAs(User::first()); // create a page with a category $this->visit(route('backend.page.create'))->type('Hallo', 'title')->type('hallo', 'slug')->select('', 'category_id')->type('Content', 'body')->press('Save')->see('alert-success'); $page = Page::whereSlug('hallo')->first(); $this->assertNotNull($page); $this->assertEquals($page->category_id, '', 'Category id saved in page'); }
/** * @test */ public function it_not_allows_update_page_to_a_frontpage() { // log in $adminUser = User::first(); $this->actingAs($adminUser); // create a page without slug $this->visit('/backend/page/create')->type('WildWest', 'title')->type('wild', 'slug')->type('Soo cool', 'body')->press(trans('crud::crud.save'))->see('alert-success'); // try to update this page without a slug $this->visit('/backend/page/2/edit')->type('Wildeast', 'title')->type('', 'slug')->type('Soo cool', 'body')->press(trans('crud::crud.save'))->see('alert-success'); $page = Page::whereTitle('Wildeast')->firstOrFail(); $this->assertEquals('wildeast', $page->slug); }
public function getUrlShow($id) { $page = Page::findOrFail($id); if (!is_null($page->topic_id)) { // page with a topic return route('page.show.topic', [$page->topic->slug, $page->slug]); } if (empty($page->slug)) { // frontpage return route('page.frontpage'); } // page without a topic return route('page.show', [$page->slug]); }
/** * Handle the event. * * @param sitemap $event * @return void */ public function handle() { $pages = Page::whereActive(true)->get(); $sitemaps = []; $domain = config('app.url') . '/'; foreach ($pages as $page) { if (empty($page->slug)) { // frontpage $sitemaps[] = new Sitemap(['title' => $page->title, 'url' => $domain]); continue; } $sitemaps[] = new Sitemap(['title' => $page->title, 'url' => $domain . $page->slug]); } return $sitemaps; }
protected function getPage($pageSlug, $topicSlug = null) { if (is_null($topicSlug)) { $query = Page::whereSlug($pageSlug); } else { $query = Topic::slug($topicSlug)->firstOrFail()->pages()->whereSlug($pageSlug); } if (Auth::check() === false || Auth::user()->hasRole('admin') === false) { $query->whereActive(true); } $page = $query->get()->first(); if (is_null($page)) { throw (new ModelNotFoundException())->setModel(Page::class); } return $page; }
/** * @test */ public function it_allows_see_simple_page_without_category_and_topic() { $page = Page::create(['title' => 'Alpaca is so cool', 'slug' => 'alpaca', 'body' => '<p>...</p>', 'html_title' => '', 'meta_robots' => '', 'meta_description' => '', 'active' => 1]); $this->visit('/alpaca')->see($page->title); }
/** * Updates a entry. * * @param $id * @param array $data * * @return bool|int */ public function updateEntry($id, array $data) { $entry = $this->getEntry($id); $data['active'] = isset($data['active']); if (empty($data['category_id'])) { $data['category_id'] = null; } if (empty($data['topic_id'])) { $data['topic_id'] = null; } if (empty($data['slug'])) { if (!empty($entry->slug) && Page::whereSlug('')->first() !== null) { $data['slug'] = app('slugify')->slugify($data['title']); } } $status = $entry->update($data); return $status; }
/** * Run the migrations. * * @return void */ public function up() { Page::create(['title' => 'Frontpage', 'slug' => '', 'body' => '<p>Let us start to create a LaravelCMF...</p>', 'html_title' => '', 'meta_robots' => '', 'meta_description' => '', 'active' => 1]); }