Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Can I use third-party validation libraries with MoonShine profile fields
    moonshine laravel


Can I use third-party validation libraries with MoonShine profile fields


Yes, you can use third-party validation libraries with MoonShine profile fields. Here's how you can integrate a popular validation library like Validator Awesome:

Steps to Use Third-Party Validation

1. Install the Validator Awesome Library: First, install the Validator Awesome package using Composer:

bash
   composer require proengsoft/laravel-jsvalidation
   

2. Publish the Validator Awesome Assets: Publish the Validator Awesome assets to your project:

bash
   php artisan vendor:publish --provider="Proengsoft\JsValidation\JsValidationServiceProvider"
   

3. Create a Custom Validator Class: Create a custom validator class that extends the Validator Awesome validator:

php
   namespace App\Validators;

   use Proengsoft\JsValidation\Facades\JsValidatorFacade;

   class ProfileValidator extends JsValidatorFacade
   {
       public function __construct()
       {
           parent::__construct([
               'name' => 'required|string|max:255',
               'email' => 'required|email|max:255',
               // Add more validation rules as needed
           ]);
       }
   }
   

4. Integrate with MoonShine: In the `config/moonshine.php` file, specify your custom validator class for the profile page:

php
   return [
       'auth' => [
           'enable' => true,
           'fields' => [
               'username' => 'email',
               'password' => 'password',
               'name' => 'name',
               'avatar' => 'avatar',
           ],
           'validators' => [
               'profile' => \App\Validators\ProfileValidator::class,
           ],
           // Other settings...
       ],
   ];
   

5. Include Validator Awesome Assets: In your MoonShine layout file (`resources/views/vendor/moonshine/layouts/app.blade.php`), include the Validator Awesome assets:

html
   @extends('moonshine::layouts.app')

   @section('content')
       @yield('content')
   @endsection

   @push('scripts')
       {!! JsValidator::formRequest(\App\Validators\ProfileValidator::class) !!}
   @endpush
   

By following these steps, you can integrate Validator Awesome (or any other third-party validation library) with MoonShine profile fields. The custom validator class will handle the validation rules, and the library's assets will be included in the MoonShine layout for client-side validation.

Remember to adjust the validation rules and class names according to your specific requirements.

Citations:
[1] https://moonshine-laravel.com/docs/resource/models-resources/resources-form
[2] https://www.youtube.com/watch?v=W9euqSpjcfE
[3] https://moonshine-laravel.com/docs/resource/advanced/advanced-authentication
[4] https://moonshine-laravel.com/docs/resource/getting-started/configuration
[5] https://github.com/rjsf-team/react-jsonschema-form/issues/145
[6] https://moonshine-laravel.com/docs/resource/advanced/advanced-form_builder
[7] https://github.com/SWEET1S/moonshine-database
[8] https://softwareengineering.stackexchange.com/questions/406858/should-a-3rd-party-user-input-validation-library-be-wrapped