How to make dynamic validation using foreach

How to make dynamic validation using foreach

Trying to do dynamic validation using foreach. Using name attributes in request input method as key and trying to append required string as value to a variable and then assigning that variable to validate method. The reason I am doing this because I realize required string needs comma after each pair and the last pair does not require.

Trying to do dynamic validation using foreach. Using name attributes in request input method as key and trying to append required string as value to a variable and then assigning that variable to validate method. The reason I am doing this because I realize required string needs comma after each pair and the last pair does not require.

$requestInputs = $request->input();

$countArr = count($requestInputs);
$flag = 1;

$validation = '';

foreach($requestInputs as $key => $val)
{

    if($flag < $countArr)
    {
        $a = "'" .$key. "'". ' => ' . '"required",';
    }else{
        $a = "'" .$key. "'". ' => ' . '"required"';
    }

    $flag++;

    // echo $a . "</br>";
    $validation = $request->validate([ $a ]);

}

// using array instead

$extraArr = array();

foreach($requestInputs as $key => $val)
{

    if($flag < $countArr)
    {
       $extraArr = array($key => '"required",');
    }else{
       $extraArr = array($key => '"required"');
    }

    $flag++;

    // echo $a . "</br>";
    $validation = $request->validate([ $a ]);

}

but this error I got {"message":"The given data was invalid.","errors":[["The 0 field is required."]]}

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

PHP variable to JavaScript In Laravel

In PHP, there is always a limitation on pass PHP variable to the javascript file. Many PHP developers, face this issue. But Laravel has one package which is directly set the variable in js. So, you can use this package for passing a variable from controller to javascript.

Clear Cache in Laravel 6.8 App using Artisan Command Interface (CLI)

In Laravel 6 tutorial, we learn how to use PHP artisan command interface (CLI) to clear the cache from Laravel 6.8 application. How To Clear Cache in Laravel 6.8 Application using Artisan Command Line Interface (CLI)? How to clear route cache using php artisan command? How to easily clear cache in Laravel application? How to clear config cache in PHP Laravel via artisan command? How to clear Laravel view cache? How to Reoptimized class in Laravel via artisan CLI?

Get Weather Data with Laravel Weather

Get Weather Data with Laravel Weather. Laravel Weather is a good package which we can use to get weather data. It's a wrapper around Open Weather Map API (Current weather). A wrapper around Open Weather Map API (Current weather)