@@ -42,6 +42,15 @@ public function __construct()
4242 $ this ->signedIn = auth ()->check ();
4343 }
4444
45+ /**
46+ * Stops the application and shows a permission error if
47+ * the application is in demo mode.
48+ */
49+ protected function preventAccessForDemoUsers ()
50+ {
51+ if (env ('APP_ENV ' , 'production ' ) === 'demo ' ) $ this ->showPermissionError ();
52+ }
53+
4554 /**
4655 * Adds the page title into the view.
4756 * @param $title
@@ -51,6 +60,18 @@ public function setPageTitle($title)
5160 view ()->share ('pageTitle ' , $ title );
5261 }
5362
63+ /**
64+ * On a permission error redirect to home and display
65+ * the error as a notification.
66+ */
67+ protected function showPermissionError ()
68+ {
69+ Session::flash ('error ' , trans ('errors.permission ' ));
70+ throw new HttpResponseException (
71+ redirect ('/ ' )
72+ );
73+ }
74+
5475 /**
5576 * Checks for a permission.
5677 *
@@ -60,15 +81,18 @@ public function setPageTitle($title)
6081 protected function checkPermission ($ permissionName )
6182 {
6283 if (!$ this ->currentUser || !$ this ->currentUser ->can ($ permissionName )) {
63- Session::flash ('error ' , trans ('errors.permission ' ));
64- throw new HttpResponseException (
65- redirect ('/ ' )
66- );
84+ $ this ->showPermissionError ();
6785 }
6886
6987 return true ;
7088 }
7189
90+ /**
91+ * Check if a user has a permission or bypass if the callback is true.
92+ * @param $permissionName
93+ * @param $callback
94+ * @return bool
95+ */
7296 protected function checkPermissionOr ($ permissionName , $ callback )
7397 {
7498 $ callbackResult = $ callback ();
0 commit comments