<?php

namespace App\Traits;

use Illuminate\Database\Eloquent\Model;

trait HandlesPrimaryKeysAsArrays {
    /**
     * @param Model $model
     *
     * @return array
     */
    private function getPrimaryKeys(Model $model): array {
        return (array) $model->getKeyName();
    }

    /**
     * @param Model $model
     *
     * @return string
     */
    private function getPrimaryKeyValuesAsString(Model $model): string {
        return implode(', ', array_map(function ($keyName) use ($model) {
            return $model->getAttribute($keyName);
        }, $this->getPrimaryKeys($model)));
    }
}
