Cachet is now a Laravel 5 app
This commit is contained in:
53
app/Http/Middleware/HasSetting.php
Normal file
53
app/Http/Middleware/HasSetting.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Middleware;
|
||||
|
||||
use CachetHQ\Cachet\Models\Setting;
|
||||
use Closure;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
|
||||
class HasSetting
|
||||
{
|
||||
/**
|
||||
* Run the has setting middleware.
|
||||
*
|
||||
* We're verifying that the given setting exists in our database. If it
|
||||
* doesn't, then we're sending the user to the setup page so that they can
|
||||
* complete the installation of Cachet on their server.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$settingName = $this->getSettingName($request);
|
||||
|
||||
try {
|
||||
$setting = Setting::where('name', $settingName)->first();
|
||||
if (!$setting || !$setting->value) {
|
||||
return Redirect::to('setup');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return Redirect::to('setup');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the setting from the request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getSettingName($request)
|
||||
{
|
||||
$actions = $request->route()->getAction();
|
||||
|
||||
return $actions['setting'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user