Skip to content

Commit

Permalink
Merge pull request #34 from asahasrabuddhe/analysis-qBvJOL
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
asahasrabuddhe authored Jul 12, 2019
2 parents 3cc1953 + 378def5 commit 900637b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ protected function getMetaData($single = false)
// result. As, there is single result in count query,
// and setting offset will not return that record
$offset = $this->query->getQuery()->offset;

if ($offset > 0) {
$this->query->offset($offset);
}
Expand Down
21 changes: 11 additions & 10 deletions src/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
use Closure;
use Carbon\Carbon;
use DateTimeInterface;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Support\Facades\DB;

class BaseModel extends Model
{
/**
Expand Down Expand Up @@ -321,10 +322,10 @@ public function save(array $options = [])
// Fill all other relations
foreach ($this->relationAttributes as $key => $relationAttribute) {
/** @var Relation $relation */
$relation = call_user_func([$this, $key]);
$relation = call_user_func([$this, $key]);
$primaryKey = $relation->getRelated()->getKeyName();
$className = get_class($relation->getRelated());
$className = get_class($relation->getRelated());

if ($relation instanceof HasOne || $relation instanceof HasMany) {
if ($relation instanceof HasOne) {
$relationAttribute = [$relationAttribute];
Expand All @@ -334,15 +335,15 @@ public function save(array $options = [])

foreach ($relationAttribute as $val) {
if ($val !== null) {
if (!isset($val[$primaryKey])) {
if (! isset($val[$primaryKey])) {
/** @var Model $model */
$model = new $className;
$model = new $className;
$val[$relationKey] = $parentId;
}else{
} else {
$model = $relation->getRelated()->find($val[$primaryKey]);
}

if (!$model) {
if (! $model) {
// Resource not found
throw new RelatedResourceNotFoundException('Resource for relation "' . $key . '" not found');
}
Expand All @@ -366,14 +367,14 @@ public function save(array $options = [])
$relationKey = explode('.', $relation->getQualifiedRelatedPivotKeyName())[1];
foreach ($relationAttribute as $val) {
if ($val !== null) {
if (!isset($val[$relationKey])) {
if (! isset($val[$relationKey])) {
throw new RelatedResourceNotFoundException('Resource for relation "' . $key . '" not found');
}

/** @var Model $model */
$model = $relation->getRelated()->find($val[$relationKey]);

if (!$model) {
if (! $model) {
// Resource not found
throw new RelatedResourceNotFoundException('Resource for relation "' . $key . '" not found');
}
Expand Down
1 change: 0 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Asahasrabuddhe\LaravelAPI\Tests;

use Illuminate\Support\Facades\DB;
use Illuminate\Database\Schema\Blueprint;
use Asahasrabuddhe\LaravelAPI\Facades\ApiRoute;
use Asahasrabuddhe\LaravelAPI\Tests\Models\Post;
Expand Down

0 comments on commit 900637b

Please sign in to comment.