|
1
|
|
|
<?php namespace Modules\Blog\Http\Controllers\Admin; |
|
2
|
|
|
|
|
3
|
|
|
use Modules\Blog\Entities\Post; |
|
4
|
|
|
use Modules\Blog\Entities\Status; |
|
5
|
|
|
use Modules\Blog\Http\Requests\CreatePostRequest; |
|
6
|
|
|
use Modules\Blog\Http\Requests\UpdatePostRequest; |
|
7
|
|
|
use Modules\Blog\Repositories\CategoryRepository; |
|
8
|
|
|
use Modules\Blog\Repositories\PostRepository; |
|
9
|
|
|
use Modules\Core\Http\Controllers\Admin\AdminBaseController; |
|
10
|
|
|
use Modules\Media\Repositories\FileRepository; |
|
11
|
|
|
|
|
12
|
|
|
class PostController extends AdminBaseController |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var PostRepository |
|
16
|
|
|
*/ |
|
17
|
|
|
private $post; |
|
18
|
|
|
/** |
|
19
|
|
|
* @var CategoryRepository |
|
20
|
|
|
*/ |
|
21
|
|
|
private $category; |
|
22
|
|
|
/** |
|
23
|
|
|
* @var FileRepository |
|
24
|
|
|
*/ |
|
25
|
|
|
private $file; |
|
26
|
|
|
/** |
|
27
|
|
|
* @var Status |
|
28
|
|
|
*/ |
|
29
|
|
|
private $status; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct( |
|
32
|
|
|
PostRepository $post, |
|
33
|
|
|
CategoryRepository $category, |
|
34
|
|
|
FileRepository $file, |
|
35
|
|
|
Status $status |
|
36
|
|
|
) { |
|
37
|
|
|
parent::__construct(); |
|
38
|
|
|
|
|
39
|
|
|
$this->post = $post; |
|
40
|
|
|
$this->category = $category; |
|
41
|
|
|
$this->file = $file; |
|
42
|
|
|
$this->status = $status; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Display a listing of the resource. |
|
47
|
|
|
* |
|
48
|
|
|
* @return \Illuminate\View\View |
|
49
|
|
|
*/ |
|
50
|
|
|
public function index() |
|
51
|
|
|
{ |
|
52
|
|
|
$posts = $this->post->all(); |
|
53
|
|
|
|
|
54
|
|
|
return view('blog::admin.posts.index', compact('posts')); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Show the form for creating a new resource. |
|
59
|
|
|
* |
|
60
|
|
|
* @return \Illuminate\View\View |
|
61
|
|
|
*/ |
|
62
|
|
|
public function create() |
|
63
|
|
|
{ |
|
64
|
|
|
$categories = $this->category->allTranslatedIn(app()->getLocale()); |
|
65
|
|
|
$statuses = $this->status->lists(); |
|
66
|
|
|
|
|
67
|
|
|
return view('blog::admin.posts.create', compact('categories', 'statuses')); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Store a newly created resource in storage. |
|
72
|
|
|
* |
|
73
|
|
|
* @param CreatePostRequest $request |
|
74
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
75
|
|
|
*/ |
|
76
|
|
|
public function store(CreatePostRequest $request) |
|
77
|
|
|
{ |
|
78
|
|
|
$this->post->create($request->all()); |
|
79
|
|
|
|
|
80
|
|
|
flash(trans('blog::messages.post created')); |
|
81
|
|
|
|
|
82
|
|
|
return redirect()->route('admin.blog.post.index'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Show the form for editing the specified resource. |
|
87
|
|
|
* |
|
88
|
|
|
* @param Post $post |
|
89
|
|
|
* @return \Illuminate\View\View |
|
90
|
|
|
*/ |
|
91
|
|
|
public function edit(Post $post) |
|
92
|
|
|
{ |
|
93
|
|
|
$thumbnail = $this->file->findFileByZoneForEntity('thumbnail', $post); |
|
94
|
|
|
$categories = $this->category->allTranslatedIn(app()->getLocale()); |
|
95
|
|
|
$statuses = $this->status->lists(); |
|
96
|
|
|
|
|
97
|
|
|
return view('blog::admin.posts.edit', compact('post', 'categories', 'thumbnail', 'statuses')); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Update the specified resource in storage. |
|
102
|
|
|
* |
|
103
|
|
|
* @param Post $post |
|
104
|
|
|
* @param UpdatePostRequest $request |
|
105
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
106
|
|
|
*/ |
|
107
|
|
|
public function update(Post $post, UpdatePostRequest $request) |
|
108
|
|
|
{ |
|
109
|
|
|
$this->post->update($post, $request->all()); |
|
110
|
|
|
|
|
111
|
|
|
flash(trans('blog::messages.post updated')); |
|
112
|
|
|
|
|
113
|
|
|
return redirect()->route('admin.blog.post.index'); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Remove the specified resource from storage. |
|
118
|
|
|
* |
|
119
|
|
|
* @param Post $post |
|
120
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
121
|
|
|
*/ |
|
122
|
|
|
public function destroy(Post $post) |
|
123
|
|
|
{ |
|
124
|
|
|
$post->tags()->detach(); |
|
125
|
|
|
|
|
126
|
|
|
$this->post->destroy($post); |
|
127
|
|
|
|
|
128
|
|
|
flash(trans('blog::messages.post deleted')); |
|
129
|
|
|
|
|
130
|
|
|
return redirect()->route('admin.blog.post.index'); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|