Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed import category has row #3138

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions app/Imports/Settings/Categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Categories extends Import
{
public $request_class = Request::class;

public $model = Model::class;

public $columns = [
'name',
'type',
Expand All @@ -33,4 +35,22 @@ public function map($row): array

return $row;
}

//This function is used in import classes. If the data in the row exists in the database, it is returned.
public function hasRow($row)
{
$has_row = $this->model::getWithoutChildren($this->columns)->each(function ($data) {
$data->setAppends([]);
$data->unsetRelations();
});

$search_value = [];

//In the model, the fields to be searched for the row are determined.
foreach ($this->columns as $key) {
$search_value[$key] = isset($row[$key]) ? $row[$key] : null;
}

return in_array($search_value, $has_row->toArray());
}
}