Files
investbrain/app/Imports/ValidatesPortfolioAccess.php
T
hackerESQ 1ef8dd9378 Feat: Adds multi currency to imports and exports (#89)
* Also adds ability for user to export configurations
2025-04-10 20:47:35 -05:00

26 lines
622 B
PHP

<?php
declare(strict_types=1);
namespace App\Imports;
use App\Models\Portfolio;
trait ValidatesPortfolioAccess
{
public function validatePortfolioAccess($collection)
{
$importingPortfolios = $collection->unique('portfolio_id')->pluck('portfolio_id');
$portfoliosWithAccess = Portfolio::fullAccess($this->backupImport->user_id)
->whereIn('id', $importingPortfolios)
->count();
if (
$importingPortfolios->count() > $portfoliosWithAccess
) {
throw new \Exception(__('You do not have access to that portfolio.'));
}
}
}