Skip to content

Commit

Permalink
Merge pull request #29 from tattersoftware/parent-null
Browse files Browse the repository at this point in the history
Template Bugs
  • Loading branch information
MGatner committed Jul 22, 2022
2 parents 3cd7cb8 + 2899a34 commit 69a5a49
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Controllers/Templates.php
Expand Up @@ -59,7 +59,7 @@ public function new($id = null): string
*/
public function create(): RedirectResponse
{
if ($this->model->insert($this->request->getPost())) {
if ($this->model->insert($this->getData())) {
return redirect()->to(site_url('emails/templates'))->with('success', 'Email template created.');
}

Expand Down Expand Up @@ -115,7 +115,7 @@ public function update($id = null): RedirectResponse
{
$template = $this->getTemplate($id);

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

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

return redirect()->back()->withInput()->with('error', $email->printDebugger([]));
}

/**
* Retrieves POST data safe for the database.
*/
protected function getData(): array
{
$data = $this->request->getPost();

if (array_key_exists('parent_id', $data)) {
$data['parent_id'] = empty($data['parent_id']) ? null : $data['parent_id'];
}

return $data;
}
}
1 change: 1 addition & 0 deletions src/Entities/Template.php
Expand Up @@ -16,6 +16,7 @@ class Template extends Entity
'deleted_at',
];
protected $casts = [
'id' => '?int',
'parent_id' => '?int',
];

Expand Down

0 comments on commit 69a5a49

Please sign in to comment.