Skip to content

Commit bc83448

Browse files
author
qiang.sun
committed
博客项目代码
0 parents  commit bc83448

File tree

170 files changed

+103227
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+103227
-0
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.yml]
15+
indent_size = 2

.env.example

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
APP_NAME=Laravel
2+
APP_ENV=local
3+
APP_KEY=
4+
APP_DEBUG=true
5+
APP_URL=http://localhost
6+
7+
LOG_CHANNEL=stack
8+
9+
DB_CONNECTION=mysql
10+
DB_HOST=127.0.0.1
11+
DB_PORT=3306
12+
DB_DATABASE=homestead
13+
DB_USERNAME=homestead
14+
DB_PASSWORD=secret
15+
16+
BROADCAST_DRIVER=log
17+
CACHE_DRIVER=file
18+
QUEUE_CONNECTION=sync
19+
SESSION_DRIVER=file
20+
SESSION_LIFETIME=120
21+
22+
REDIS_HOST=127.0.0.1
23+
REDIS_PASSWORD=null
24+
REDIS_PORT=6379
25+
26+
MAIL_DRIVER=smtp
27+
MAIL_HOST=smtp.mailtrap.io
28+
MAIL_PORT=2525
29+
MAIL_USERNAME=null
30+
MAIL_PASSWORD=null
31+
MAIL_ENCRYPTION=null
32+
MAIL_FROM_ADDRESS=
33+
MAIL_FROM_NAME=
34+
35+
PUSHER_APP_ID=
36+
PUSHER_APP_KEY=
37+
PUSHER_APP_SECRET=
38+
PUSHER_APP_CLUSTER=mt1
39+
40+
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
41+
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

.gitattributes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
* text=auto
2+
*.css linguist-vendored
3+
*.scss linguist-vendored
4+
*.js linguist-vendored
5+
CHANGELOG.md export-ignore

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/node_modules
2+
/public/hot
3+
/public/storage
4+
/storage/*.key
5+
/vendor
6+
/.idea
7+
/.vscode
8+
/nbproject
9+
/.vagrant
10+
Homestead.json
11+
Homestead.yaml
12+
npm-debug.log
13+
yarn-error.log
14+
.env
15+
.phpunit.result.cache

app/Console/Kernel.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace App\Console;
4+
5+
use Illuminate\Console\Scheduling\Schedule;
6+
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
7+
8+
class Kernel extends ConsoleKernel
9+
{
10+
/**
11+
* The Artisan commands provided by your application.
12+
*
13+
* @var array
14+
*/
15+
protected $commands = [
16+
//
17+
];
18+
19+
/**
20+
* Define the application's command schedule.
21+
*
22+
* @param \Illuminate\Console\Scheduling\Schedule $schedule
23+
* @return void
24+
*/
25+
protected function schedule(Schedule $schedule)
26+
{
27+
$schedule->command('queue:work')->everyMinute();
28+
}
29+
30+
/**
31+
* Register the commands for the application.
32+
*
33+
* @return void
34+
*/
35+
protected function commands()
36+
{
37+
$this->load(__DIR__.'/Commands');
38+
39+
require base_path('routes/console.php');
40+
}
41+
}

app/Exceptions/Handler.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Exception;
6+
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
7+
8+
class Handler extends ExceptionHandler
9+
{
10+
/**
11+
* A list of the exception types that are not reported.
12+
*
13+
* @var array
14+
*/
15+
protected $dontReport = [
16+
//
17+
];
18+
19+
/**
20+
* A list of the inputs that are never flashed for validation exceptions.
21+
*
22+
* @var array
23+
*/
24+
protected $dontFlash = [
25+
'password',
26+
'password_confirmation',
27+
];
28+
29+
/**
30+
* Report or log an exception.
31+
*
32+
* @param \Exception $exception
33+
* @return void
34+
*/
35+
public function report(Exception $exception)
36+
{
37+
parent::report($exception);
38+
}
39+
40+
/**
41+
* Render an exception into an HTTP response.
42+
*
43+
* @param \Illuminate\Http\Request $request
44+
* @param \Exception $exception
45+
* @return \Illuminate\Http\Response
46+
*/
47+
public function render($request, Exception $exception)
48+
{
49+
return parent::render($request, $exception);
50+
}
51+
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Admin;
4+
5+
use App\Http\Requests\PostCreateRequest;
6+
use App\Http\Requests\PostUpdateRequest;
7+
use App\Jobs\PostFormFields;
8+
use App\Models\Post;
9+
use App\Models\Tag;
10+
use Carbon\Carbon;
11+
use Illuminate\Http\Request;
12+
use App\Http\Controllers\Controller;
13+
use Illuminate\Http\Response;
14+
15+
class PostController extends Controller
16+
{
17+
protected $fieldList = [
18+
'title' => '',
19+
'subtitle' => '',
20+
'page_image' => '',
21+
'content' => '',
22+
'meta_description' => '',
23+
'is_draft' => "0",
24+
'publish_date' => '',
25+
'publish_time' => '',
26+
'layout' => 'blog.layouts.post',
27+
'tags' => [],
28+
];
29+
30+
/**
31+
* Display a listing of the posts.
32+
*/
33+
public function index()
34+
{
35+
return view('admin.post.index', ['posts' => Post::all()]);
36+
}
37+
38+
/**
39+
* Show the new post form
40+
*/
41+
public function create()
42+
{
43+
$fields = $this->fieldList;
44+
45+
$when = Carbon::now()->addHour();
46+
$fields['publish_date'] = $when->format('Y-m-d');
47+
$fields['publish_time'] = $when->format('g:i A');
48+
49+
foreach ($fields as $fieldName => $fieldValue) {
50+
$fields[$fieldName] = old($fieldName, $fieldValue);
51+
}
52+
53+
$data = array_merge(
54+
$fields,
55+
['allTags' => Tag::all()->pluck('tag')->all()]
56+
);
57+
58+
return view('admin.post.create', $data);
59+
}
60+
61+
/**
62+
* Store a newly created Post
63+
*
64+
* @param PostCreateRequest $request
65+
*/
66+
public function store(PostCreateRequest $request)
67+
{
68+
$post = Post::create($request->postFillData());
69+
$post->syncTags($request->get('tags', []));
70+
71+
return redirect()
72+
->route('post.index')
73+
->with('success', '新文章创建成功.');
74+
}
75+
76+
/**
77+
* Show the post edit form
78+
*
79+
* @param int $id
80+
* @return Response
81+
*/
82+
public function edit($id)
83+
{
84+
$fields = $this->fieldsFromModel($id, $this->fieldList);
85+
86+
foreach ($fields as $fieldName => $fieldValue) {
87+
$fields[$fieldName] = old($fieldName, $fieldValue);
88+
}
89+
90+
$data = array_merge(
91+
$fields,
92+
['allTags' => Tag::all()->pluck('tag')->all()]
93+
);
94+
95+
return view('admin.post.edit', $data);
96+
}
97+
98+
/**
99+
* 更新文章
100+
*
101+
* @param PostUpdateRequest $request
102+
* @param $id
103+
* @return \Illuminate\Http\RedirectResponse
104+
*/
105+
public function update(PostUpdateRequest $request, $id)
106+
{
107+
$post = Post::findOrFail($id);
108+
$post->fill($request->postFillData());
109+
$post->save();
110+
$post->syncTags($request->get('tags', []));
111+
112+
if ($request->action === 'continue') {
113+
return redirect()
114+
->back()
115+
->with('success', '文章已保存.');
116+
}
117+
118+
return redirect()
119+
->route('post.index')
120+
->with('success', '文章已保存.');
121+
}
122+
123+
/**
124+
* Remove the specified resource from storage.
125+
*
126+
* @param int $id
127+
* @return Response
128+
*/
129+
public function destroy($id)
130+
{
131+
$post = Post::findOrFail($id);
132+
$post->tags()->detach();
133+
$post->delete();
134+
135+
return redirect()
136+
->route('post.index')
137+
->with('success', '文章已删除.');
138+
}
139+
140+
/**
141+
* Return the field values from the model
142+
*
143+
* @param integer $id
144+
* @param array $fields
145+
* @return array
146+
*/
147+
private function fieldsFromModel($id, array $fields)
148+
{
149+
$post = Post::findOrFail($id);
150+
151+
$fieldNames = array_keys(array_except($fields, ['tags']));
152+
153+
$fields = ['id' => $id];
154+
foreach ($fieldNames as $field) {
155+
$fields[$field] = $post->{$field};
156+
}
157+
158+
$fields['tags'] = $post->tags->pluck('tag')->all();
159+
160+
return $fields;
161+
}
162+
}

0 commit comments

Comments
 (0)