Skip to content

Commit 44753e2

Browse files
committed
groups with companies/employees and minor fixes
1 parent ad7d449 commit 44753e2

File tree

8 files changed

+11
-188
lines changed

8 files changed

+11
-188
lines changed

app/Group.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function getPlannerNameAttribute()
6060
{
6161
if(is_object($this->planner) && $this->planner->exists)
6262
return $this->planner->name;
63+
return null;
6364
}
6465

6566
/**

app/Http/Controllers/Companies/Employees/EmployeesController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function index()
3939
* @var $company Company
4040
*/
4141
$company = \Auth::user();
42-
return $company->employees;
42+
return $company->employees()->with('groups.planner')->get();
4343
}
4444

4545
/**
@@ -68,7 +68,7 @@ public function store(EmployeeRequest $request)
6868
public function show($id)
6969
{
7070
//
71-
$employee = Employee::findOrFail($id);
71+
$employee = Employee::with('groups.planner')->findOrFail($id);
7272
$this->authorize($employee);
7373
return $employee;
7474
}

app/Http/Controllers/Companies/Groups/GroupsController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public function index()
3838
* @var $company Company
3939
*/
4040
$company = \Auth::user();
41-
return $company->groups;
41+
$groups = $company->groups()->with('planner')->get();
42+
return $groups;
4243
}
4344

4445
/**
@@ -63,7 +64,7 @@ public function store(GroupRequest $request)
6364
*/
6465
public function show($id)
6566
{
66-
$group = Group::findOrFail($id);
67+
$group = Group::with('planner')->findOrFail($id);
6768
$this->authorize($group);
6869
return $group;
6970
}

app/Http/Controllers/Employees/EmployeesController.php

Lines changed: 0 additions & 87 deletions
This file was deleted.

app/Http/Controllers/Employees/GroupsController.php

Lines changed: 0 additions & 89 deletions
This file was deleted.

app/Http/routes.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,4 @@
7979
Route::post('reset', ['as' => 'companies.auth.reset', 'uses'=>'PasswordController@postReset']);
8080
});
8181
});
82-
83-
Route::resource('employees', 'EmployeesController');
84-
Route::resource('groups', 'GroupsController');
8582
});

tests/Companies/Employees/EmployeesControllerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testIndex()
2626
$company = \plunner\Company::findOrFail(1);
2727
$response = $this->actingAs($company)->json('GET', '/companies/employees');
2828
$response->assertResponseOk();
29-
$response->seeJsonEquals($company->employees->toArray());
29+
$response->seeJsonEquals($company->employees()->with('groups.planner')->get()->toArray());
3030
}
3131

3232
public function testErrorIndex()
@@ -41,7 +41,7 @@ public function testShow()
4141
* @var $company \plunner\Company
4242
*/
4343
$company = \plunner\Company::findOrFail(1);
44-
$employee = $company->employees->first();
44+
$employee = $company->employees()->with('groups.planner')->first();
4545
$response = $this->actingAs($company)->json('GET', '/companies/employees/'.$employee->id);
4646
$response->assertResponseOk();
4747
$response->seeJsonEquals($employee->toArray());
@@ -123,7 +123,7 @@ public function testSameEmailDifferentCompany()
123123
public function testDelete()
124124
{
125125
$company = \plunner\Company::findOrFail(1);
126-
$employee = $company->employees->first();
126+
$employee = $company->employees()->with('groups.planner')->first();
127127
$id = $employee->id;
128128

129129
//employee exists

tests/Companies/Groups/GroupControllerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testIndexAllGroups()
3636
$response = $this->actingAs($this->company)->json('GET', '/companies/groups');
3737

3838
$response->assertResponseOk();
39-
$response->seeJsonEquals($this->company->groups->toArray());
39+
$response->seeJsonEquals($this->company->groups()->with('planner')->get()->toArray());
4040
}
4141

4242
public function testErrorIndexNoCompany()
@@ -48,7 +48,7 @@ public function testErrorIndexNoCompany()
4848

4949
public function testShowSpecificGroup()
5050
{
51-
$group = $this->company->groups->first();
51+
$group = $this->company->groups()->with('planner')->first();
5252

5353
$response = $this->actingAs($this->company)->json('GET', '/companies/groups/' . $group->id);
5454

0 commit comments

Comments
 (0)