This commit is contained in:
hackerESQ
2024-08-30 20:22:28 -05:00
parent df1071d628
commit 8b86dace13
14 changed files with 137 additions and 139 deletions
+12 -18
View File
@@ -3,7 +3,6 @@
namespace App\Imports\Sheets;
use App\Models\Portfolio;
use Illuminate\Validation\Rule;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
@@ -14,24 +13,19 @@ class PortfoliosSheet implements ToCollection, WithValidation, WithHeadingRow, S
{
public function collection(Collection $portfolios)
{
Portfolio::withoutEvents(function () use ($portfolios) {
foreach ($portfolios as $portfolio) {
foreach ($portfolios as $portfolio) {
Portfolio::unguard();
auth()->user()->portfolios()
->where(['id' => $portfolio['portfolio_id']])
->orWhere(['title' => $portfolio['title']])
->firstOr(function () use ($portfolio) {
return Portfolio::make()->forceFill([
'id' => $portfolio['portfolio_id'] ?? null,
'title' => $portfolio['title'],
'wishlist' => $portfolio['wishlist'] ?? false,
'notes' => $portfolio['notes'],
])->save();
});
}
});
Portfolio::updateOrCreate([
'id' => $portfolio['portfolio_id']
], [
'id' => $portfolio['portfolio_id'] ?? null,
'title' => $portfolio['title'],
'wishlist' => $portfolio['wishlist'] ?? false,
'notes' => $portfolio['notes'],
]);
}
}
public function rules(): array