<?php

namespace App\Traits;

use Illuminate\Support\Str;

trait PivotData
{
    /**
     * @param string $index
     * @param $request
     * @return array
     */
    private function preparePivotData($request, string $index): array
    {
        if(empty($request->post($index))) return [];

        $return = [];
        foreach($request->post($index) as $uuid) {
            $return[$uuid] = [
                'uuid'         => (string) Str::uuid(),
                'created_at'   => now(),
                'created_uuid' => $request->user()->uuid,
                'updated_at'   => now(),
                'updated_uuid' => $request->user()->uuid
            ];
        }

        return $return;
    }
}
