From acd3f3bc7cedbe8b8f6f4adc7bf3213e9d501f76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihan=20=C5=9Eent=C3=BCrk?= <53110792+CihanSenturk@users.noreply.github.com> Date: Wed, 21 Feb 2024 11:01:38 +0300 Subject: [PATCH] fixed import category has row --- app/Imports/Settings/Categories.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/Imports/Settings/Categories.php b/app/Imports/Settings/Categories.php index 2aa2b9efbe7..fca5af8fa75 100644 --- a/app/Imports/Settings/Categories.php +++ b/app/Imports/Settings/Categories.php @@ -10,6 +10,8 @@ class Categories extends Import { public $request_class = Request::class; + public $model = Model::class; + public $columns = [ 'name', 'type', @@ -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()); + } }