PHP code example of jshibu86 / validator

1. Go to this page and download the library: Download jshibu86/validator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jshibu86 / validator example snippets


[
    'name' => ['nullable', 'string', 'max:255'],
    'phone' => ['
bash
use Shibu\ValidationGenerator\Services\ValidationGeneratorService;

class YourController extends Controller
{
    protected $validationService;

    public function __construct(ValidationGeneratorService $validationService)
    {
        $this->validationService = $validationService;
    }

    public function store(Request $request)
    {
        $tableName = 'students'; // Pass the table name dynamically or hardcoded
        $data = $request->all();

        $rules = $this->validationService->generateValidationRules($tableName);

        // Perform validation
        $validator = \Validator::make($data, $rules);

        if ($validator->fails()) {
            return response()->json($validator->errors(), 422);
        }

        // If validation passes, save the data
        // Example:
        // Student::create($data);

        return response()->json(['message' => 'Data saved successfully']);
    }
}

bash
php artisan validate-table {tableName}
bash
php artisan validate-table users
bash
php artisan vendor:publish