-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Employees controller (with tests) for company
- Loading branch information
Showing
6 changed files
with
350 additions
and
7 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace plunner\Http\Requests\Companies; | ||
|
||
use plunner\Company; | ||
use plunner\Http\Requests\Request; | ||
|
||
class EmployeeRequest extends Request | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'name' => 'required|max:255', | ||
'email' => 'required|email|max:255|unique:employees,email,NULL,id,company_id,'.$this->user()->id, | ||
'password' => 'required|confirmed|min:6', | ||
]; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace plunner\Policies; | ||
|
||
use plunner\Company; | ||
use plunner\Employee; | ||
|
||
class EmployeePolicy | ||
{ | ||
/** | ||
* Create a new policy instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* @param Company $company | ||
* @param Employee $employee | ||
* @return bool | ||
*/ | ||
public function index(Company $company, Employee $employee) | ||
{ | ||
return $this->userCheck($company, $employee); | ||
} | ||
|
||
/** | ||
* @param Company $company | ||
* @param Employee $employee | ||
* @return bool | ||
*/ | ||
public function store(Company $company, Employee $employee) | ||
{ | ||
return $this->userCheck($company, $employee); | ||
} | ||
|
||
/** | ||
* @param Company $company | ||
* @param Employee $employee | ||
* @return bool | ||
*/ | ||
public function update(Company $company, Employee $employee) | ||
{ | ||
return $this->userCheck($company, $employee); | ||
} | ||
|
||
/** | ||
* @param Company $company | ||
* @param Employee $employee | ||
* @return bool | ||
*/ | ||
public function show(Company $company, Employee $employee) | ||
{ | ||
$ret = $this->userCheck($company, $employee); | ||
return $ret; | ||
} | ||
|
||
/** | ||
* @param Company $company | ||
* @param Employee $employee | ||
* @return bool | ||
*/ | ||
public function destroy(Company $company, Employee $employee) | ||
{ | ||
return $this->userCheck($company, $employee); | ||
} | ||
|
||
/** | ||
* @param Company $company | ||
* @param Employee $employee | ||
* @return bool | ||
*/ | ||
private function userCheck(Company $company, Employee $employee) | ||
{ | ||
return $company->id === $employee->company_id; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="bootstrap/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Application Test Suite"> | ||
<directory>./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">app/</directory> | ||
</whitelist> | ||
</filter> | ||
<php> | ||
<env name="APP_ENV" value="testing"/> | ||
<env name="CACHE_DRIVER" value="array"/> | ||
<env name="SESSION_DRIVER" value="array"/> | ||
<env name="QUEUE_DRIVER" value="sync"/> | ||
</php> | ||
</phpunit> |
Oops, something went wrong.