-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from ezra-obiwale/wip
Created model helper trait
- Loading branch information
Showing
3 changed files
with
26 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |