@php use App\Models\Plugin; $position = $position ?? 'head'; $allowedPositions = ['head', 'body', 'footer']; if (!in_array($position, $allowedPositions, true)) { $position = 'head'; } $plugins = cache()->remember('frontend_active_plugins_' . $position, now()->addMinutes(10), function () use ($position) { return Plugin::query() ->active() ->orderBy('sort_order') ->get(['name', 'head_code', 'body_code', 'footer_code']) ->filter(function ($plugin) use ($position) { return match ($position) { 'head' => filled($plugin->head_code), 'body' => filled($plugin->body_code), 'footer' => filled($plugin->footer_code), default => false, }; }); }); @endphp @foreach ($plugins as $plugin) @if ($position === 'head') {!! $plugin->head_code !!} @elseif ($position === 'body') {!! $plugin->body_code !!} @elseif ($position === 'footer') {!! $plugin->footer_code !!} @endif @endforeach