<?php

namespace App\Providers;

use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\View;
use App\Models\Message;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        DB::listen(function($query) {
            Log::info("Query : " . $query->sql);
        });

        // view paginate
        Paginator::useBootstrapFour();

        // View Composer untuk navbar
        View::composer('*', function ($view) {
            $view->with('messages', Message::latest()->take(5)->get());
        });
    }
}