Skip to content

Commit

Permalink
fixed import category has row
Browse files Browse the repository at this point in the history
  • Loading branch information
CihanSenturk committed Feb 21, 2024
1 parent 0702847 commit acd3f3b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/Imports/Settings/Categories.php
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());
}
}

0 comments on commit acd3f3b

Please sign in to comment.