<?php

namespace App\Providers;

use Illuminate\Http\Resources\Json\Resource;
use Illuminate\Support\Facades\Validator;
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()
    {
        Resource::withoutWrapping();
        Validator::extend('htmlMax', function ($attribute, $htmlValue, $parameters, $validator) {
            $validator->requireParameterCount(1, $parameters, 'htmlMax');
            $value = strip_tags($htmlValue);
            return $validator->validateMax($attribute, $value, $parameters);
        });

        Validator::replacer('htmlMax', function ($message, $attribute, $rule, $parameters) {
            return str_replace(':max', $parameters[0], $message);
        });
    }
}
