Closed ryross closed 2 years ago
Thanks @ryross. Can you please add test(s)?
For avoid many commits you can squash them
git reset --soft HEAD~
git reset --soft HEAD~
git reset --soft HEAD~
git commit --verbose --amend -C HEAD
git push origin -f
git reset --soft HEAD~
uncommit
git commit --verbose --amend -C HEAD
add to the last commit
git push origin -f
force push with new commit
Maybe a global function could help, like this
if (! function_exists('getLaravelMayorVersion')) {
function getLaravelMayorVersion () {
$version = explode('.', app()->version());
return (int)$version[0];
}
}
public function smallerTrackingTask()
{
$rel = $this->hasOne(TrackingTask::class, ['booking_id', 'vehicle_id'], ['booking_id', 'vehicle_id'])-
return getLaravelMayorVersion() < 8 ? $rel : $rel->ofMany('id', 'min');
}
public function latestTrackingTask()
{
$rel = $this->hasOne(TrackingTask::class, ['booking_id', 'vehicle_id'], ['booking_id', 'vehicle_id']);
return getLaravelMayorVersion() < 8 ? $rel : $rel->latestOfMany();
}
public function oldestTrackingTask()
{
$rel = $this->hasOne(TrackingTask::class, ['booking_id', 'vehicle_id'], ['booking_id', 'vehicle_id']);
return getLaravelMayorVersion() < 8 ? $rel : $rel->oldestOfMany();
}
public function test_Compoships_hasOneOrMany_saveMany()
{
////**
if(getLaravelMayorVersion() >= 8) {
$this->assertEquals($expectedData[0], $allocation->smallerTrackingTask->toArray());
$this->assertEquals($expectedData[0], $allocation->oldestTrackingTask->toArray());
$this->assertEquals($expectedData[2], $allocation->latestTrackingTask->toArray());
}
////**
}
I merged the implementation with tests https://github.com/topclaudy/compoships/pull/128
This PR adds support for ofMany(). See https://laravel-news.com/one-of-many-eloquent-relationship