/
var
/
www
/
html
/
gnet
/
app
/
Providers
/
Upload File
HOME
<?php namespace App\Providers; use App\Models\Category; use App\Models\MetaTags; use Illuminate\Support\Facades\Request; use Illuminate\Support\Facades\Validator; 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; $lastSegment = determineLastSegment($firstSegment, $lastSegment); // Mencari data dari database yang mengandung page_url yang cocok $metaTags = MetaTags::where('page_url', $lastSegment)->first(); // get product categories $categories = Category::all(); $view->with(compact('metaTags', 'firstSegment', 'currentPath', 'categories')); }); function determineLastSegment($firstSegment, $lastSegment) { if ($lastSegment === '') { return 'home'; } if ($firstSegment === 'product' && !in_array($lastSegment, ['product', 'material-atap', 'material-pelengkap', 'material-partisi', 'material-periklanan'])) { return 'product-details'; } if ($firstSegment === 'blogs') { return ($lastSegment !== 'blogs') ? 'blog-details' : $lastSegment; } return $lastSegment; } Validator::extend('recaptcha', 'App\\Validators\\ReCaptcha@validate'); } }