<?php

namespace App\Providers;

use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);

        Blade::directive('monthDate', function ($expression) {
            $dateFormat = isset($expression) ? "echo ($expression)->format('F j, Y');" : "undefined";
            return "<?php $dateFormat ?>";
        });

        DB::listen(function($query){  // для распечатки запросов к БД
            file_put_contents(storage_path('logs/sqlRequests.log'), $query->sql . PHP_EOL, FILE_APPEND);
//           dump($query);
        });
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
