|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Http\Controllers; |
| 4 | + |
| 5 | +use App\Article; |
| 6 | +use Illuminate\Http\Request; |
| 7 | +use Phased\Routing\Facades\Phase; |
| 8 | +use Phased\State\Facades\Vuex; |
| 9 | + |
| 10 | +class BlogController extends Controller |
| 11 | +{ |
| 12 | + public function HomePage() |
| 13 | + { |
| 14 | + // Pull the fake articles from our fake helper |
| 15 | + // generator |
| 16 | + $fakeArticles = $this->getFakerArticles(); |
| 17 | + |
| 18 | + // Add them to our vuex store |
| 19 | + // $store.state.articles.recent |
| 20 | + $fakeArticles->toVuex('articles', 'recents'); |
| 21 | + |
| 22 | + // return the Phase view |
| 23 | + return Phase::view(); |
| 24 | + } |
| 25 | + |
| 26 | + public function SingleArticle($article) |
| 27 | + { |
| 28 | + // Find the article that matches the slug |
| 29 | + // With real database models we would use Route Model binding |
| 30 | + // but since this is all just fake data, we will just match |
| 31 | + // the slug string here |
| 32 | + $fakeArticle = $this->getFakerArticles()->firstWhere('slug', $article); |
| 33 | + |
| 34 | + // Set it as the active article |
| 35 | + // $store.state.articles.active |
| 36 | + $fakeArticle->toVuex('articles', 'active'); |
| 37 | + |
| 38 | + // return the Phase view |
| 39 | + return Phase::view(); |
| 40 | + } |
| 41 | + |
| 42 | + public function AboutPage() |
| 43 | + { |
| 44 | + $faker = \Faker\Factory::create(); |
| 45 | + $faker->seed(1234); |
| 46 | + Vuex::state([ |
| 47 | + 'bio' => $faker->paragraphs(3, false) |
| 48 | + ]); |
| 49 | + |
| 50 | + return Phase::view(); |
| 51 | + } |
| 52 | + |
| 53 | + public function ContactPage() |
| 54 | + { |
| 55 | + $faker = \Faker\Factory::create(); |
| 56 | + $faker->seed(4321); |
| 57 | + Vuex::state([ |
| 58 | + 'contact' => $faker->paragraphs(3, false) |
| 59 | + ]); |
| 60 | + |
| 61 | + return Phase::view(); |
| 62 | + } |
| 63 | + /** |
| 64 | + * not a view |
| 65 | + */ |
| 66 | + private function getFakerArticles() |
| 67 | + { |
| 68 | + // Generate a collection of fake blog articles... |
| 69 | + // Our faker has a common seed, so this will always |
| 70 | + // generate the same articles |
| 71 | + return factory(Article::class, 10)->make(); |
| 72 | + } |
| 73 | +} |
0 commit comments