Created
August 18, 2016 13:41
-
-
Save rob1121/82178ca126a53e92853e3111a0585aed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function store(Request $request) | |
{ | |
$db = new Db($request, new CompanyDatabase); | |
$db->add(); | |
return $db->getResult(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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