Changed functions in Person model such that they return a Relation instead of an
Eloquent collection and adjusted the PersonController accordingly.
This commit is contained in:
@@ -19,9 +19,9 @@ class PeopleController extends Controller
|
|||||||
|
|
||||||
public function show(Person $person)
|
public function show(Person $person)
|
||||||
{
|
{
|
||||||
$memberStates = $person->getMemberStates();
|
$memberStates = $person->memberStates;
|
||||||
$targets = $person->getTargets();
|
$targets = $person->targets;
|
||||||
$actuals = $person->getActuals();
|
$actuals = $person->actuals;
|
||||||
|
|
||||||
return view('people.show', compact('person', 'memberStates', 'targets',
|
return view('people.show', compact('person', 'memberStates', 'targets',
|
||||||
'actuals'));
|
'actuals'));
|
||||||
|
|||||||
+16
-20
@@ -21,7 +21,7 @@ class Person extends Model
|
|||||||
*/
|
*/
|
||||||
public function isMember()
|
public function isMember()
|
||||||
{
|
{
|
||||||
$latest = $this->getMemberStates()->last();
|
$latest = $this->memberStates->last();
|
||||||
|
|
||||||
if (is_null($latest)) {
|
if (is_null($latest)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -39,7 +39,7 @@ class Person extends Model
|
|||||||
*/
|
*/
|
||||||
public function wasMember()
|
public function wasMember()
|
||||||
{
|
{
|
||||||
return !($this->getMemberStates()->isEmpty());
|
return !($this->memberStates->isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -49,13 +49,9 @@ class Person extends Model
|
|||||||
*/
|
*/
|
||||||
public static function active()
|
public static function active()
|
||||||
{
|
{
|
||||||
return Person::join('member_states', 'people.id', '=', 'member_states.person_id')
|
return Person::whereHas('memberStates', function($memberState) {
|
||||||
->where('member_states.leaving_date', null)
|
$memberState->where('leaving_date', '=', null);
|
||||||
->select('person_id as id', 'title', 'name_or_company',
|
})->get();
|
||||||
'surname', 'date_of_birth', 'city', 'street',
|
|
||||||
'postal_code', 'email', 'mobile', 'phone',
|
|
||||||
'joining_date', 'leaving_date')
|
|
||||||
->get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -65,7 +61,7 @@ class Person extends Model
|
|||||||
*/
|
*/
|
||||||
public function activeSince()
|
public function activeSince()
|
||||||
{
|
{
|
||||||
$latest = $this->hasMany('\App\MemberState')
|
$latest = $this->memberStates
|
||||||
->orderBy('joining_date', 'desc')
|
->orderBy('joining_date', 'desc')
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
@@ -79,7 +75,7 @@ class Person extends Model
|
|||||||
*/
|
*/
|
||||||
public function activeTime()
|
public function activeTime()
|
||||||
{
|
{
|
||||||
$activeTimes = $this->hasMany('\App\MemberState')->get();
|
$activeTimes = $this->memberStates;
|
||||||
|
|
||||||
$diff = 0;
|
$diff = 0;
|
||||||
|
|
||||||
@@ -101,11 +97,11 @@ class Person extends Model
|
|||||||
/*
|
/*
|
||||||
* Get all member state records associated with a person.
|
* Get all member state records associated with a person.
|
||||||
*
|
*
|
||||||
* @return Illuminate\Database\Eloquent\Collection
|
* @return Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
*/
|
*/
|
||||||
public function getMemberStates()
|
public function memberStates()
|
||||||
{
|
{
|
||||||
return $this->hasMany('\App\MemberState')->orderBy('joining_date')->get();
|
return $this->hasMany('\App\MemberState')->orderBy('joining_date');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
@@ -115,20 +111,20 @@ class Person extends Model
|
|||||||
/*
|
/*
|
||||||
* Get all targets associated with a person.
|
* Get all targets associated with a person.
|
||||||
*
|
*
|
||||||
* @return Illuminate\Database\Eloquent\Collection
|
* @return Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
*/
|
*/
|
||||||
public function getTargets()
|
public function targets()
|
||||||
{
|
{
|
||||||
return $this->hasMany('\App\PersonTarget')->orderBy('date')->get();
|
return $this->hasMany('\App\PersonTarget')->orderBy('date');
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get all actuals associated with a person.
|
* Get all actuals associated with a person.
|
||||||
*
|
*
|
||||||
* @return Illuminate\Database\Eloquent\Collection
|
* @return Illuminate\Database\Eloquent\Relations\HasManyThrough
|
||||||
*/
|
*/
|
||||||
public function getActuals()
|
public function actuals()
|
||||||
{
|
{
|
||||||
return $this->hasManyThrough('\App\SubBooking', '\App\PersonTarget')->get();
|
return $this->hasManyThrough('\App\SubBooking', '\App\PersonTarget');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user