/
var
/
www
/
html
/
gnet
/
gnet
/
App
/
Providers
/
Upload File
HOME
<?php namespace App\Providers; use App\Models\MetaTags; use Illuminate\Support\Facades\Request; use Illuminate\Support\Facades\View; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /** * Register any application services. * * @return void */ public function register() { // } /** * Bootstrap any application services. * * @return void */ public function boot() { if($this->app->environment('production')) { \URL::forceScheme('https'); } View::composer('*', function ($view) { $currentPath = Request::path(); // Mendapatkan bagian path dari URL saat ini $segments = explode('/', $currentPath); // Memisahkan path $lastSegment = end($segments); // Mendapatkan bagian terakhir dari path // untuk halaman dengan dynamic url $firstSegment = isset($segments[0]) ? $segments[0] : null; if ($lastSegment === '') { $lastSegment = 'home'; } elseif ($firstSegment === 'product') { $lastSegment = 'product-details'; } elseif ($firstSegment === 'blog') { $lastSegment = 'blog-details'; } // Mencari data dari database yang mengandung page_url yang cocok $metaTags = MetaTags::where('page_url', $lastSegment)->first(); $view->with(compact('metaTags', 'firstSegment', 'currentPath')); }); } }