Reworked site setup, added SingleOrFail()

This commit is contained in:
Deon George
2021-07-01 19:41:12 +10:00
parent 036ab07329
commit c34da6bfb8
12 changed files with 663 additions and 486 deletions

View File

@@ -26,19 +26,26 @@ class SetSite
*/
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 = new Site;
if ($so->getTable() AND Schema::hasTable($so->getTable()))
$so = Site::where('url',$request->root())->first();
$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) || (! $so->exists))
$so = (new Site)->sample();
if (! $so) {
if ($request->ajax())
abort(404);
$so = (new Site);
}
// Set who we are in SETUP.
Config::set('SITE_SETUP',$so);
View::share('so',$so);
if (! $request->ajax())
View::share('so',$so);
return $next($request);
}