-
app/Http/ViewComposers/LazyViewComposer.php
Open in GitHubuse Illuminate\View\View; class LazyViewComposer { public function compose(View $view) { $view->with('usesInternetExplorer', $this->usesInternetExplorer()); } private function usesInternetExplorer(): bool { if (app()->runningInConsole()) { return false; } $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? ''; if (preg_match('~MSIE|Internet Explorer~i', $userAgent)) { return true; } if (strpos($userAgent, 'Trident/7.0; rv:11.0') !== false) { return true; } return false; } }
-
app/Providers/ViewServiceProvider.php
Open in GitHubuse App\Http\ViewComposers\LazyViewComposer; use Illuminate\Support\Facades\View; use Illuminate\Support\ServiceProvider; class ViewServiceProvider extends ServiceProvider { public function register() { View::composer('front.components.lazy', LazyViewComposer::class); } }
-
resources/views/front/components/lazy.blade.php
Open in GitHub@if($usesInternetExplorer) {{ $slot }} @else <div data-lazy> <template> {{ $slot }} </template> </div> @endif