Skip to content

Commit 69a5a49

Browse files
authored
Merge pull request #29 from tattersoftware/parent-null
Template Bugs
2 parents 3cd7cb8 + 2899a34 commit 69a5a49

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/Controllers/Templates.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function new($id = null): string
5959
*/
6060
public function create(): RedirectResponse
6161
{
62-
if ($this->model->insert($this->request->getPost())) {
62+
if ($this->model->insert($this->getData())) {
6363
return redirect()->to(site_url('emails/templates'))->with('success', 'Email template created.');
6464
}
6565

@@ -115,7 +115,7 @@ public function update($id = null): RedirectResponse
115115
{
116116
$template = $this->getTemplate($id);
117117

118-
if ($this->model->update($template->id, $this->request->getPost())) {
118+
if ($this->model->update($template->id, $this->getData())) {
119119
return redirect()->back()->with('success', 'Email template updated.');
120120
}
121121

@@ -181,4 +181,18 @@ public function send_commit($id = null): RedirectResponse
181181

182182
return redirect()->back()->withInput()->with('error', $email->printDebugger([]));
183183
}
184+
185+
/**
186+
* Retrieves POST data safe for the database.
187+
*/
188+
protected function getData(): array
189+
{
190+
$data = $this->request->getPost();
191+
192+
if (array_key_exists('parent_id', $data)) {
193+
$data['parent_id'] = empty($data['parent_id']) ? null : $data['parent_id'];
194+
}
195+
196+
return $data;
197+
}
184198
}

src/Entities/Template.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Template extends Entity
1616
'deleted_at',
1717
];
1818
protected $casts = [
19+
'id' => '?int',
1920
'parent_id' => '?int',
2021
];
2122

0 commit comments

Comments
 (0)