|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace JeroenG\GuestPass\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use JeroenG\GuestPass\GuestPassFacade as GuestPass; |
|
6
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs; |
|
7
|
|
|
use Illuminate\Routing\Controller as BaseController; |
|
8
|
|
|
use Illuminate\Foundation\Validation\ValidatesRequests; |
|
9
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
|
10
|
|
|
|
|
11
|
|
|
class Access extends BaseController |
|
12
|
|
|
{ |
|
13
|
|
|
use AuthorizesRequests, DispatchesJobs, ValidatesRequests; |
|
14
|
|
|
|
|
15
|
|
|
public function __invoke($owner, $key) |
|
16
|
|
|
{ |
|
17
|
|
|
// First, get the Guest Pass and corresponding object models. |
|
18
|
|
|
$pass = GuestPass::getGuestPass($key); |
|
19
|
|
|
$object = (new $pass->object_model)->findOrFail($pass->object_id); |
|
20
|
|
|
|
|
21
|
|
|
// Check if there is a view handle saved in the database. |
|
22
|
|
|
if ($pass->view == null) { |
|
23
|
|
|
// If not, see if a view named after the object model exists. |
|
24
|
|
|
$viewName = strtolower(class_basename($object)); |
|
25
|
|
|
if (file_exists(resource_path('views/guests/'.$viewName.'.blade.php'))) { |
|
26
|
|
|
return view('guests/'.$viewName, ['object' => $object]); |
|
27
|
|
|
} |
|
28
|
|
|
// If there is a view handle saved, check if the file exists. |
|
29
|
|
|
} elseif (file_exists(resource_path('views/guests/'.$pass->view.'.blade.php'))) { |
|
30
|
|
|
return view('guests/'.$$pass->view, ['object' => $object, 'guestpass' => $pass]); |
|
31
|
|
|
} |
|
32
|
|
|
// In case neither exists, abort. |
|
33
|
|
|
abort(404); |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|