Skip to content

Commit

Permalink
Merge pull request #8 from ezra-obiwale/wip
Browse files Browse the repository at this point in the history
Created model helper trait
  • Loading branch information
ezra-obiwale authored Jan 4, 2018
2 parents ae1df1f + 119eba5 commit 27b1f38
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.0.1

Created model helper trait

## 3.0.0

Changed response structure to:
Expand Down
16 changes: 1 addition & 15 deletions src/Models/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,6 @@

abstract class Model extends iModel
{

public function toArray()
{
$fillable = $this->fillable;
$fillable[] = 'id';
// Show only fillables
$array = collect(parent::toArray())
->only($fillable)
->all();
// Add loaded relations
foreach (array_keys($this->relations) as $relation) {
$array[$relation] = $this->$relation;
}
return $array;
}
use Traits\Helper;

}
21 changes: 21 additions & 0 deletions src/Models/Traits/Helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Laraquick\Models\Traits;

trait Helper {

public function toArray()
{
$fillable = $this->fillable;
$fillable[] = 'id';
// Show only fillables
$array = collect(parent::toArray())
->only($fillable)
->all();
// Add loaded relations
foreach (array_keys($this->relations) as $relation) {
$array[$relation] = $this->$relation;
}
return $array;
}
}

0 comments on commit 27b1f38

Please sign in to comment.