Completed
Push — master ( f40de5...7f000e )
by Stephen
01:41
created

BlogDefaults::createAboutPage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
1
<?php
2
3
namespace App\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Str;
7
use Wink\WinkAuthor;
8
use Wink\WinkPage;
9
use Wink\WinkPost;
10
11
class BlogDefaults extends Command
12
{
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'blog:defaults';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Add default database entries  like first blog post and about me';
26
27
    /**
28
     * Create a new command instance.
29
     *
30
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
31
     */
32
    public function __construct()
33
    {
34
        parent::__construct();
35
    }
36
37
    /**
38
     * Execute the console command.
39
     *
40
     * @return int
41
     */
42
    public function handle()
43
    {
44
        $this->createBlogFirstPost();
45
        $this->comment('First blog post created');
46
47
        $this->createAboutPage();
48
        $this->comment('About page created');
49
50
        return 0;
51
    }
52
53
    private function createBlogFirstPost()
54
    {
55
        $title = 'Getting Started with Laravel Lite Blog';
56
57
        $slug = Str::slug($title);
58
59
        $body = 'Lite Blog a minimal full fledged blog generator (frontend & backend)  built with tailwindcss and wink a laravel publishing platform by Mohamed Said.
60
        The frontend is a replicate of jigsaw blog template. I made a blog post on how to get started. <a href="http://stephenjude.me/articles/lite-blog-a-laravel-blog-generator">Here is the link :)</a>';
61
62
        if (WinkPost::whereSlug($slug)->first()) {
63
            return;
64
        }
65
66
        WinkPost::create([
67
            'id' => Str::uuid(),
68
            'title' => $title,
69
            'excerpt' => $body,
70
            'slug' => $slug,
71
            'body' => $body,
72
            'published' => true,
73
            'author_id' => WinkAuthor::first()->id,
74
            'featured_image' => 'https://ucarecdn.com/a571a7d3-c4d5-400d-8805-c1b6e2e5afc0/homepage.PNG',
75
            'featured_image_caption' => '',
76
            'publish_date' => now(),
77
        ]);
78
    }
79
80
    private function createAboutPage()
81
    {
82
        $title = 'About Me';
83
84
        $slug = Str::slug($title);
85
86
        if (WinkPage::whereSlug($slug)->first()) {
87
            return;
88
        }
89
90
        WinkPage::create([
91
            'id' => Str::uuid(),
92
            'title' => $title,
93
            'slug' => $slug,
94
            'body' => 'Hey, I\'m Stephen Jude. I code. I write about code. I teach how I write code. I talk at conferences about how I teach to code.',
95
        ]);
96
    }
97
}
98