la_bloger/app/Http/Middleware/ResolveChannel.php
2026-04-22 16:21:35 +02:00

34 lines
810 B
PHP

<?php
namespace App\Http\Middleware;
use App\Models\Channel;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class ResolveChannel
{
public function handle(Request $request, Closure $next): Response
{
$hostname = $request->getHost();
$channel = Channel::with('prefixes')
->where('hostname', $hostname)
->first();
if (! $channel) {
abort(404);
}
app()->instance(Channel::class, $channel);
view()->share('channel', $channel);
view()->addNamespace('theme', array_values(array_filter([
resource_path('views/themes/' . $channel->template),
resource_path('views/themes/default'),
], 'is_dir')));
return $next($request);
}
}