Skip to content

Instantly share code, notes, and snippets.

@rob1121
Created August 18, 2016 13:41
Show Gist options
  • Save rob1121/82178ca126a53e92853e3111a0585aed to your computer and use it in GitHub Desktop.
Save rob1121/82178ca126a53e92853e3111a0585aed to your computer and use it in GitHub Desktop.
public function store(Request $request)
{
$db = new Db($request, new CompanyDatabase);
$db->add();
return $db->getResult();
}
//abstract class contains basic form validation and file validation
class CompanyDatabase extends DocumentAbstract
{
protected function validationRules($id = NULL)
{
return [
'owner' => "required|unique:companies,owner," . $id .
",id,revision," . $this->request->revision .
",control_id," . $this->request->control_id .
",file_name," . $this->request->file_name .
",date_upload," . $this->request->date_upload,
'revision' => 'required|min:2',
'control_id' => 'required',
'category_id' => 'required',
'category_name' => 'required',
'file_name' => 'required',
'date_upload' => 'required',
'file' => "required|mimes:pdf"
];
}
public function addNewDataToTable()
{
$newCompanySpecification = company::create($this->request->all());
$this->setResult($newCompanySpecification);
}
public function getResult() {
return $this->result;
}
}
class Db
{
protected $db;
private $request;
public function __construct($request, DocumentInterface $db)
{
$this->request = $request;
$this->db = $db;
}
public function add()
{
$this->db->validateRequest($this->request);
$this->db->addNewDataToTable();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment