使用相同的验证函数php laravel验证所有对象值

enter image description here

Above is the result of dd() one of the object , right now what i did is

//$car is a object variable
$car->corporate_id = some_function($car->corporate_id);
$car->corporate_name = some_function($car->corporate_name);
$car->member_id = some_function($car->member_id);

Instead doing the above ways , how can i achieve something like

 $data = some_function($car);
//it will go through all $car properties and run the same validation

can someone tell me how to achieve this?

I found it , first foreach the object , for example $cars is object ,

foreach($cars as $car)
{
     $carr = $car->map(function ($item, $key)
             {

               //code logic goes here
               // $key variable is the index key of the object
               // $item variable is value of the object
                $data = $item + 1;        
               return $data ;
             });

         //after this you can simply access the object attribute like usual
         $carr->car_number;
         $carr->car_name;


}

but this is solution is using laravel Collection and you also can turn an array into collection by simply call

  $collection = collect($anyArray); // make sure to include Illuminate\Support\Collection this class 
                                   //in order for to use the collection functionality

the function body like this

if(!is_object($car)) return 'function expect a car object';

if(isset($car->corporate_id))
    $car->corporate_id = some_other_function($car->corporate_id);

if(isset($car->corporate_name))
    $car->corporate_id = some_other_function($car->corporate_name);
 ...........

return $car;