52 lines
1002 B
PHP
52 lines
1002 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Illuminate\Support\Facades\Config;
|
|
use Illuminate\Support\Facades\View;
|
|
use Closure;
|
|
|
|
use App\Models\Site;
|
|
|
|
/**
|
|
* 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)
|
|
{
|
|
$so = new Site;
|
|
|
|
if ($so->getTable() AND Schema::hasTable($so->getTable()))
|
|
$so = Site::where('url',$request->root())->single();
|
|
|
|
if ($so && ! $so->active)
|
|
abort(404);
|
|
|
|
// If we dont exist, we'll return a fake model.
|
|
if (! $so) {
|
|
if ($request->ajax())
|
|
abort(404);
|
|
|
|
$so = (new Site);
|
|
}
|
|
|
|
// Set who we are in SETUP.
|
|
Config::set('site',$so);
|
|
if (! $request->ajax())
|
|
View::share('site',$so);
|
|
|
|
return $next($request);
|
|
}
|
|
} |