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\ForumCategory; |
7
|
|
|
use Taskforcedev\LaravelForum\Helpers\UserHelper; |
8
|
|
|
use Taskforcedev\LaravelForum\Helpers\Sanitizer; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class BaseController |
12
|
|
|
* @package Taskforcedev\LaravelForum\Http\Controllers |
13
|
|
|
*/ |
14
|
|
|
class BaseController extends Controller |
15
|
|
|
{ |
16
|
|
|
public $sanitizer; |
17
|
|
|
|
18
|
|
|
public function __construct() |
19
|
|
|
{ |
20
|
|
|
$this->sanitizer = new Sanitizer(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Determine if the user can moderate the forums. |
25
|
|
|
* @return boolean |
26
|
|
|
*/ |
27
|
|
|
protected function canModerate() |
28
|
|
|
{ |
29
|
|
|
$user = $this->getUser(); |
30
|
|
|
|
31
|
|
|
if ($user->name == 'Guest' && $user->email == '[email protected]') { |
32
|
|
|
return false; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
if (method_exists($user, 'can')) { |
36
|
|
|
return $user->can('forum-moderate'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
// If no method of authorizing return false; |
40
|
|
|
return false; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function canCreateForums() |
44
|
|
|
{ |
45
|
|
|
try { |
46
|
|
|
$user = Auth::user(); |
47
|
|
|
return $user->can('create', Forum::class); |
48
|
|
|
} catch (\Exception $e) { |
49
|
|
|
return false; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Builds data required for views. |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
protected function buildData($data = []) |
58
|
|
|
{ |
59
|
|
|
$data['user'] = $this->getUser(); |
60
|
|
|
$data['layout'] = $this->getLayout(); |
61
|
|
|
$data['categories'] = ForumCategory::with('forums')->get(); |
|
|
|
|
62
|
|
|
$data['sitename'] = $this->getSitename(); |
63
|
|
|
$data['wysiwyg'] = config('laravel-forum.wysiwyg'); |
64
|
|
|
$data['sanitizer'] = $this->sanitizer; |
65
|
|
|
$data['userHelper'] = new UserHelper(); |
66
|
|
|
|
67
|
|
|
return $data; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
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: