adds validation to imports
This commit is contained in:
@@ -3,12 +3,14 @@
|
||||
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;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use Maatwebsite\Excel\Concerns\WithValidation;
|
||||
|
||||
class PortfoliosSheet implements ToCollection, WithHeadingRow, SkipsEmptyRows
|
||||
class PortfoliosSheet implements ToCollection, WithValidation, WithHeadingRow, SkipsEmptyRows
|
||||
{
|
||||
// use Importable;
|
||||
|
||||
@@ -17,12 +19,12 @@ class PortfoliosSheet implements ToCollection, WithHeadingRow, SkipsEmptyRows
|
||||
foreach ($portfolios as $portfolio) {
|
||||
|
||||
auth()->user()->portfolios()
|
||||
->where(['id' => $portfolio['id']])
|
||||
->where(['id' => $portfolio['portfolio_id']])
|
||||
->orWhere(['title' => $portfolio['title']])
|
||||
->firstOr(function () use ($portfolio) {
|
||||
|
||||
return Portfolio::make()->forceFill([
|
||||
'id' => $portfolio['id'] ?? null,
|
||||
'id' => $portfolio['portfolio_id'] ?? null,
|
||||
'title' => $portfolio['title'],
|
||||
'wishlist' => $portfolio['wishlist'] ?? false,
|
||||
'notes' => $portfolio['notes'],
|
||||
@@ -30,4 +32,14 @@ class PortfoliosSheet implements ToCollection, WithHeadingRow, SkipsEmptyRows
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'portfolio_id' => ['sometimes', 'nullable'],
|
||||
'title' => ['required', 'string'],
|
||||
'wishlist' => ['sometimes', 'nullable', 'boolean'],
|
||||
'notes' => ['sometimes', 'nullable', 'string'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user