2017-12-07 23:04:02 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
2024-07-04 05:03:11 +00:00
|
|
|
use Illuminate\Http\Request;
|
2018-04-10 11:23:13 +00:00
|
|
|
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
|
|
|
|
{
|
|
|
|
/**
|
2024-07-04 05:03:11 +00:00
|
|
|
* @param Request $request
|
|
|
|
* @param Closure $next
|
2017-12-07 23:04:02 +00:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2024-07-04 05:03:11 +00:00
|
|
|
public function handle(Request $request,Closure $next)
|
2017-12-07 23:04:02 +00:00
|
|
|
{
|
2018-05-20 12:53:14 +00:00
|
|
|
$so = new Site;
|
2018-04-10 11:23:13 +00:00
|
|
|
|
2018-07-31 04:11:00 +00:00
|
|
|
if ($so->getTable() AND Schema::hasTable($so->getTable()))
|
2021-07-01 09:41:12 +00:00
|
|
|
$so = Site::where('url',$request->root())->single();
|
|
|
|
|
|
|
|
if ($so && ! $so->active)
|
|
|
|
abort(404);
|
2017-12-07 23:04:02 +00:00
|
|
|
|
|
|
|
// If we dont exist, we'll return a fake model.
|
2021-07-01 09:41:12 +00:00
|
|
|
if (! $so) {
|
|
|
|
if ($request->ajax())
|
|
|
|
abort(404);
|
|
|
|
|
|
|
|
$so = (new Site);
|
|
|
|
}
|
2017-12-07 23:04:02 +00:00
|
|
|
|
|
|
|
// Set who we are in SETUP.
|
2021-12-17 04:58:24 +00:00
|
|
|
Config::set('site',$so);
|
2021-07-01 09:41:12 +00:00
|
|
|
if (! $request->ajax())
|
2021-07-01 23:12:34 +00:00
|
|
|
View::share('site',$so);
|
2017-12-07 23:04:02 +00:00
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
2018-05-20 12:53:14 +00:00
|
|
|
}
|