Skip to content

Commit 7a507ca

Browse files
committed
Complete: Installation setup - WIP: Controllers/Views/Routes
1 parent 9d4289a commit 7a507ca

File tree

6 files changed

+72
-77
lines changed

6 files changed

+72
-77
lines changed

README.md

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -87,49 +87,40 @@ This package requires Laravel 5.8 or higher, PHP 7.2 or higher and a database th
8787

8888
## Installation
8989

90+
> Note: Laravel Blogger requires you to have user authentication in place prior to installation.
91+
For Laravel 5.* based projects run the `make:auth` Artisan command.
92+
For Laravel 6.* based projects please see the official guide to get started.
93+
9094
You can install the package via composer:
9195

9296
```bash
9397
composer require chrisjk123/laravel-blogger
9498
```
9599

96-
Publish the migrations with:
100+
Publish the primary configuration file using the `blog:install` Artisan command:
97101

98102
```bash
99-
php artisan vendor:publish --provider="Chriscreates\Blog\BloggerServiceProvider" --tag="migrations"
100-
php artisan migrate
101-
```
102-
103-
You can optionally publish the config file with:
104-
105-
```bash
106-
php artisan vendor:publish --provider="Chriscreates\Blog\BloggerServiceProvider" --tag="config"
103+
php artisan blog:install
107104
```
108105

109106
This is the contents of the published config file, if your `User` class is
110107
within a different directory or has a different primary key it can be changed here.
111108

112-
Furthermore, the settings for allowing commenting on posts is set here, the default
113-
is set to true as well as guest commenting.
114-
115109
```php
116-
return [
117-
/*
118-
* User: the default path to the User model in Laravel and primary key
119-
*/
120-
'user' => [
121-
'user_class' => \App\User::class,
122-
'user_key_name' => 'id',
123-
],
124-
125-
/*
126-
* Post: allow commenting on posts / allow guest commenting on posts
127-
*/
128-
'posts' => [
129-
'allow_comments' => true,
130-
'allow_guest_comments' => true,
131-
],
132-
];
110+
/*
111+
|--------------------------------------------------------------------------
112+
| User relations
113+
|--------------------------------------------------------------------------
114+
|
115+
| This is the default path to the User model in Laravel and primary key.
116+
| You are free to change this path to anything you like.
117+
|
118+
*/
119+
120+
'user' => [
121+
'user_class' => \App\User::class,
122+
'user_key_name' => 'id',
123+
],
133124
```
134125

135126
## Local testing
@@ -166,6 +157,34 @@ $user->posts;
166157
$user->comments;
167158
```
168159

160+
Furthermore, in the configuration file, the default is set to true for
161+
allowing both user and public commenting on posts is set here.
162+
163+
```php
164+
/*
165+
|--------------------------------------------------------------------------
166+
| Post commenting options
167+
|--------------------------------------------------------------------------
168+
|
169+
| The default for commenting on posts is enabled, as well as guest
170+
| commenting. Feel free to change these conditions to false.
171+
|
172+
*/
173+
174+
'posts' => [
175+
'allow_comments' => true,
176+
'allow_guest_comments' => true,
177+
],
178+
```
179+
180+
You can get setup quickly by using the `blog:setup` Artisan command.
181+
This publishes the routes, controllers and views. Optionally you can seed the
182+
database with `factory()` data by specifying the data `blog:setup --data` option.
183+
184+
```bash
185+
php artisan blog:setup --data
186+
```
187+
169188
### Changelog
170189

171190
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

database/seeds/PostsTableSeeder.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/BlogServiceProvider.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ private function handleRoutes()
7878
*/
7979
private function routeConfiguration()
8080
{
81-
// TODO
8281
return [
8382
'namespace' => 'Blog\Http\Controllers',
8483
'prefix' => config('blog.path'),
@@ -112,11 +111,6 @@ private function handlePublishing()
112111
__DIR__.'/../database/factories/' => database_path('factories'),
113112
], 'blog-factories');
114113

115-
// TODO: Are these really needed?
116-
$this->publishes([
117-
__DIR__.'/../database/seeds/' => database_path('seeds'),
118-
], 'blog-seeders');
119-
120114
$this->publishes([
121115
__DIR__.'/../config/blog.php' => config_path('blog.php'),
122116
], 'blog-config');

src/Console/Commands/InstallCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ class InstallCommand extends Command
3030
*/
3131
public function handle()
3232
{
33-
$this->callSilent('vendor:publish', ['--tag' => 'blog-factories']);
34-
$this->callSilent('vendor:publish', ['--tag' => 'blog-seeders']);
3533
$this->callSilent('vendor:publish', ['--tag' => 'blog-config']);
3634
$this->callSilent('migrate');
3735

src/Console/Commands/SetupCommand.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class SetupCommand extends Command
1717
*
1818
* @var string
1919
*/
20-
protected $signature = 'blog:setup {--data : Specifies that demo data should be seeded}';
20+
protected $signature = 'blog:setup
21+
{--data : Setup the database with demo data}';
2122

2223
/**
2324
* The console command description.
@@ -33,17 +34,30 @@ class SetupCommand extends Command
3334
*/
3435
public function handle()
3536
{
37+
if ( ! file_exists(config_path('blog.php'))) {
38+
$this->error("You haven't published the config file.");
39+
40+
if ($this->confirm('Publish the config file?')) {
41+
$this->call('blog:install');
42+
} else {
43+
return;
44+
}
45+
}
46+
3647
// TODO:
3748
// Controllers
3849
// Routes
3950
// Views?
4051
41-
// Optionally seed the database with demo data
4252
if ($this->option('data')) {
4353
$this->seed();
54+
} elseif ($this->confirm(
55+
'Would you like to setup the database with demo data?'
56+
)) {
57+
$this->seed();
4458
}
4559

46-
$this->info('Setup complete');
60+
$this->info('Setup complete.');
4761
}
4862

4963
/**
@@ -53,14 +67,13 @@ public function handle()
5367
*/
5468
private function seed()
5569
{
56-
// TODO: Check that blog:install has been run before this blog:setup
70+
$this->callSilent('vendor:publish', ['--tag' => 'blog-factories']);
5771

58-
// Publish factories
59-
$files = collect(
60-
array_diff(scandir(__DIR__.'/../../../database/factories/'), array('.', '..'))
61-
)->each(function ($file) {
62-
copy(__DIR__."/../../../database/factories/{$file}", database_path('factories')."/{$file}");
63-
});
72+
// $files = collect(
73+
// array_diff(scandir(__DIR__.'/../../../database/factories/'), array('.', '..'))
74+
// )->each(function ($file) {
75+
// copy(__DIR__."/../../../database/factories/{$file}", database_path('factories')."/{$file}");
76+
// });
6477

6578
// Create data
6679
factory(Post::class, 20)

src/Listeners/StoreViewData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ class StoreViewData
1414
*/
1515
public function handle(PostViewed $event)
1616
{
17-
logger('something happened.');
17+
$event->post->increment('views');
1818
}
1919
}

0 commit comments

Comments
 (0)