April 2026 waren Wirtschaft Feedback
This commit is contained in:
parent
02f2a4c23e
commit
9ce711d6b2
167 changed files with 25278 additions and 8518 deletions
58
app/Repositories/SupplierRepository.php
Normal file
58
app/Repositories/SupplierRepository.php
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\Supplier;
|
||||
|
||||
class SupplierRepository
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public function create(array $data): Supplier
|
||||
{
|
||||
$supplier = Supplier::create($this->extractSupplierAttributes($data));
|
||||
$this->syncCategories($supplier, $data['supplier_category_ids'] ?? []);
|
||||
|
||||
return $supplier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public function update(Supplier $supplier, array $data): Supplier
|
||||
{
|
||||
$supplier->update($this->extractSupplierAttributes($data));
|
||||
$this->syncCategories($supplier, $data['supplier_category_ids'] ?? []);
|
||||
|
||||
return $supplier->fresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int|string>|null $categoryIds
|
||||
*/
|
||||
public function syncCategories(Supplier $supplier, array $categoryIds): void
|
||||
{
|
||||
$ids = array_values(array_filter(array_map('intval', $categoryIds)));
|
||||
|
||||
$supplier->supplierCategories()->sync($ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function extractSupplierAttributes(array $data): array
|
||||
{
|
||||
return collect($data)->only([
|
||||
'name',
|
||||
'url',
|
||||
'contact_person',
|
||||
'email',
|
||||
'phone',
|
||||
'country_id',
|
||||
'notes',
|
||||
'active',
|
||||
])->all();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue