This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
site-base/app/Http/Middleware/SetSite.php

54 lines
1.0 KiB
PHP
Raw Permalink Normal View History

2017-12-07 23:04:02 +00:00
<?php
namespace App\Http\Middleware;
use Illuminate\Support\Facades\Schema;
2017-12-07 23:04:02 +00:00
use Closure;
use App\Models\{Site};
use Config;
use View;
use Theme;
/**
* Class SetSite
* This class is responsible for setting our site settings based on the URL of a request
*
* @package App\Http\Middleware
*/
class SetSite
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
// @todo Figure out how to know if this is an API call - and deny it if it's not in the database.
$so = NULL;
if (Schema::hasTable('site'))
{
$so = Site::where('url',$request->root())
->orwhere('devurl',$request->root())
// @todo With an API call, we would use ->firstorfail();
->first();
}
2017-12-07 23:04:02 +00:00
// If we dont exist, we'll return a fake model.
if (! $so) {
$so = (new Site)->sample();
}
Theme::set($so->theme);
// Set who we are in SETUP.
Config::set('SITE_SETUP',$so);
View::share('so',$so);
return $next($request);
}
}