Skip to content

Commit 573fee6

Browse files
Merge pull request Ashishkumbhar01#33 from donartme/edit-postdata-onconflict
Added support for on_conflict to PostData function to enable optional…
2 parents f3f825f + 3fa0051 commit 573fee6

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/Functions.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,23 @@ public function getSingleData($table=null, $query=[])
3030
}
3131
}
3232

33-
public function postData($table=null, $query=[])
33+
public function postData($table=null, $query=[], $on_conflict=null)
3434
{
35-
if (!isset($table)) {
36-
echo "Please provide your Supabase table name.";
37-
} elseif (!isset($query)) {
38-
echo "Please provide your data.";
39-
} else {
40-
$path = "$this->url/$table";
41-
$html = $this->grab($path, "POST", json_encode($query));
42-
return $html;
43-
}
35+
if (!isset($table)) {
36+
echo "Please provide your Supabase table name.";
37+
} elseif (!isset($query)) {
38+
echo "Please provide your data.";
39+
} else {
40+
// If $on_conflict is provided, append to the path
41+
if (!empty($on_conflict)) {
42+
$path = "$this->url/$table?on_conflict=$on_conflict";
43+
} else {
44+
$path = "$this->url/$table";
45+
}
46+
47+
$html = $this->grab($path, "POST", json_encode($query));
48+
return $html;
49+
}
4450
}
4551

4652
public function updateData($table=null, ?int $id=null, $query=[])

0 commit comments

Comments
 (0)