43 lines
849 B
PHP
43 lines
849 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use App\Models\{Setup,Site};
|
|
use Config;
|
|
use View;
|
|
use Theme;
|
|
|
|
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.
|
|
$so = Setup::where('url',$request->root())
|
|
->orwhere('urldev',$request->root())
|
|
// @todo With an API call, we would use ->firstorfail();
|
|
->first();
|
|
|
|
// If we dont exist, we'll return an empty model.
|
|
if (! $so) {
|
|
$so = new Setup;
|
|
$so->site = new Site;
|
|
}
|
|
|
|
Theme::set('metronic-fe');
|
|
|
|
// Set who we are in SETUP.
|
|
Config::set('SITE_SETUP',$so);
|
|
View::share('so',$so);
|
|
|
|
return $next($request);
|
|
}
|
|
}
|