|
1
|
|
|
<?php namespace Taskforcedev\LaravelForum\Http\Controllers; |
|
2
|
|
|
|
|
3
|
|
|
use \Auth; |
|
4
|
|
|
use \Schema; |
|
5
|
|
|
use Taskforcedev\LaravelSupport\Http\Controllers\Controller; |
|
6
|
|
|
use Taskforcedev\LaravelForum\Models\Forum; |
|
7
|
|
|
use Taskforcedev\LaravelForum\Models\ForumCategory; |
|
8
|
|
|
use Taskforcedev\LaravelForum\Helpers\UserHelper; |
|
9
|
|
|
use Taskforcedev\LaravelForum\Helpers\Sanitizer; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class BaseController |
|
13
|
|
|
* @package Taskforcedev\LaravelForum\Http\Controllers |
|
14
|
|
|
*/ |
|
15
|
|
|
class BaseController extends Controller |
|
16
|
|
|
{ |
|
17
|
|
|
public $sanitizer; |
|
18
|
|
|
|
|
19
|
|
|
public function __construct() |
|
20
|
|
|
{ |
|
21
|
|
|
$this->sanitizer = new Sanitizer(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Determine if the user can moderate the forums. |
|
26
|
|
|
* @return boolean |
|
27
|
|
|
*/ |
|
28
|
|
|
protected function canModerate() |
|
29
|
|
|
{ |
|
30
|
|
|
$user = $this->getUser(); |
|
31
|
|
|
|
|
32
|
|
|
if ($user->name == 'Guest' && $user->email == '[email protected]') { |
|
33
|
|
|
return false; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
if (method_exists($user, 'can')) { |
|
37
|
|
|
return $user->can('forum-moderate'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
// If no method of authorizing return false; |
|
41
|
|
|
return false; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function canCreateForums() |
|
45
|
|
|
{ |
|
46
|
|
|
if (!Auth::check()) { |
|
47
|
|
|
return false; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
try { |
|
51
|
|
|
$user = Auth::user(); |
|
52
|
|
|
return $user->can('create', Forum::class); |
|
53
|
|
|
} catch (\Exception $e) { |
|
54
|
|
|
return false; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Builds data required for views. |
|
60
|
|
|
* @return array |
|
61
|
|
|
*/ |
|
62
|
|
|
protected function buildData($data = []) |
|
63
|
|
|
{ |
|
64
|
|
|
$user = $this->getUser(); |
|
65
|
|
|
$data['user'] = $user; |
|
66
|
|
|
$data['layout'] = $this->getLayout(); |
|
67
|
|
|
$data['categories'] = ForumCategory::with('forums')->get(); |
|
|
|
|
|
|
68
|
|
|
$data['sitename'] = $this->getSitename(); |
|
69
|
|
|
$data['wysiwyg'] = config('laravel-forum.wysiwyg'); |
|
70
|
|
|
$data['sanitizer'] = $this->sanitizer; |
|
71
|
|
|
$data['userHelper'] = new UserHelper(); |
|
72
|
|
|
if (Auth::check()) { |
|
73
|
|
|
$data['isAdmin'] = $user->can('create', Forum::class); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return $data; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: