1
|
|
|
<?php namespace Taskforcedev\LaravelForum\Http\Controllers; |
2
|
|
|
|
3
|
|
|
use \Schema; |
4
|
|
|
use Illuminate\Http\Request; |
5
|
|
|
use Taskforcedev\LaravelForum\Models\Forum; |
6
|
|
|
use Taskforcedev\LaravelForum\Models\ForumPost; |
7
|
|
|
use Taskforcedev\LaravelForum\Models\ForumReply; |
8
|
|
|
use Taskforcedev\LaravelForum\Models\ForumCategory; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class AdminController |
12
|
|
|
* @package Taskforcedev\LaravelForum\Http\Controllers |
13
|
|
|
*/ |
14
|
|
|
class AdminController extends BaseController |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Admin index. |
18
|
|
|
* @return mixed |
19
|
|
|
*/ |
20
|
|
|
public function index() |
21
|
|
|
{ |
22
|
|
|
// Check if the user is able to create forums. |
23
|
|
|
if (!$this->canCreateForums()) { |
24
|
|
|
return redirect()->route('laravel-forum.index'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
$data = $this->buildData(); |
28
|
|
|
|
29
|
|
|
$data['counts'] = [ |
30
|
|
|
'forum' => (new Forum)->getCount(), |
31
|
|
|
'category' => (new ForumCategory)->getCount(), |
32
|
|
|
'post' => (new ForumPost)->getCount(), |
33
|
|
|
'reply' => (new ForumReply)->getCount(), |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
return view('laravel-forum::admin/index', $data); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return mixed |
41
|
|
|
*/ |
42
|
|
|
public function forums() |
43
|
|
|
{ |
44
|
|
|
// Check if the user is able to create forums. |
45
|
|
|
if (!$this->canCreateForums()) { |
46
|
|
|
return redirect()->route('laravel-forum.index'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$data = $this->buildData(); |
50
|
|
|
$data['categories'] = ForumCategory::all(); |
51
|
|
|
$data['forums'] = Forum::orderBy('category_id')->get(); |
52
|
|
|
return view('laravel-forum::admin/forums', $data); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return mixed |
57
|
|
|
*/ |
58
|
|
View Code Duplication |
public function categories() |
59
|
|
|
{ |
60
|
|
|
// Check if the user is able to create forums. |
61
|
|
|
if (!$this->canCreateForums()) { |
62
|
|
|
return redirect()->route('laravel-forum.index'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$data = $this->buildData(); |
66
|
|
|
$data['categories'] = ForumCategory::all(); |
67
|
|
|
return view('laravel-forum::admin/categories', $data); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
View Code Duplication |
public function forumForm() |
71
|
|
|
{ |
72
|
|
|
// Check if the user is able to create forums. |
73
|
|
|
if (!$this->canCreateForums()) { |
74
|
|
|
return redirect()->route('laravel-forum.index'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$data = $this->buildData(); |
78
|
|
|
$data['categories'] = ForumCategory::all(); |
79
|
|
|
return view('laravel-forum::admin.forum.create', $data); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function categoryForm() |
83
|
|
|
{ |
84
|
|
|
// Check if the user is able to create forums. |
85
|
|
|
if (!$this->canCreateForums()) { |
86
|
|
|
return redirect()->route('laravel-forum.index'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$data = $this->buildData(); |
90
|
|
|
return view('laravel-forum::admin.category.create', $data); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function canCreateForums() |
94
|
|
|
{ |
95
|
|
|
try { |
96
|
|
|
$user = Auth::user(); |
97
|
|
|
return $user->can('create', Forum::class); |
98
|
|
|
} catch (\Exception $e) { |
99
|
|
|
return false; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|