Skip to content

Instantly share code, notes, and snippets.

@cyberfly
Last active July 8, 2023 03:55
Show Gist options
  • Save cyberfly/c0e050a28f42de82dc2db0cb3a4792e7 to your computer and use it in GitHub Desktop.
Save cyberfly/c0e050a28f42de82dc2db0cb3a4792e7 to your computer and use it in GitHub Desktop.
<!--list errors, formatted-->
<?= validation_list_errors() ?>
<!--errors array-->
<?php $errors = validation_errors(); var_dump($errors); ?>
<!--check if errors not empty, and list it-->
<?php if (!empty(validation_errors())) : ?>
<div class="alert alert-danger" role="alert">
<?= validation_list_errors() ?>
</div>
<?php endif ?>
<!--show single error-->
<?= validation_show_error('description') ?>
public function store()
{
$rules = [
'title' => 'required',
'description' => 'required',
];
if (! $this->validate($rules)) {
return redirect()->back()->withInput();
}
$data = [
'title' => $this->request->getPost('title'),
'description' => $this->request->getPost('description'),
];
$department_model = new Department();
$department = $department_model->insert($data);
session()->setFlashdata('success', 'Department created');
return redirect()->to('/departments');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment