osb/app/Http/Middleware/SetSite.php

45 lines
1017 B
PHP
Raw Normal View History

2017-12-07 23:04:02 +00:00
<?php
namespace App\Http\Middleware;
use Illuminate\Support\Facades\Schema;
2021-06-29 03:18:52 +00:00
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\View;
2017-12-07 23:04:02 +00:00
use Closure;
2018-08-01 07:09:38 +00:00
use App\Models\Site;
2017-12-07 23:04:02 +00:00
/**
* 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.
2018-05-20 12:53:14 +00:00
$so = new Site;
2018-07-31 04:11:00 +00:00
if ($so->getTable() AND Schema::hasTable($so->getTable()))
2021-06-29 03:18:52 +00:00
$so = Site::where('url',$request->root())->first();
2017-12-07 23:04:02 +00:00
// If we dont exist, we'll return a fake model.
2021-06-29 03:18:52 +00:00
if ((! $so) || (! $so->exists))
2017-12-07 23:04:02 +00:00
$so = (new Site)->sample();
// Set who we are in SETUP.
Config::set('SITE_SETUP',$so);
View::share('so',$so);
return $next($request);
}
2018-05-20 12:53:14 +00:00
}