osb/app/Http/Middleware/SetSite.php
Deon George 3ff34af7f0
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 37s
Create Docker Image / Final Docker Image Manifest (push) Successful in 9s
Update laravel framework from 9 to 11, removed some old packages
2024-07-04 15:03:11 +10:00

51 lines
982 B
PHP

<?php
namespace App\Http\Middleware;
use Illuminate\Http\Request;
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
{
/**
* @param Request $request
* @param Closure $next
* @return mixed
*/
public function handle(Request $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);
}
}