-
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.
fix transformed, cast, mutaded values by using attributesToArray
- Loading branch information
Mads Møller
committed
Sep 5, 2018
1 parent
17dfde3
commit cf5c1ff
Showing
5 changed files
with
110 additions
and
6 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
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,49 @@ | ||
<?php | ||
|
||
namespace Napp\Core\Api\Tests\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Post extends Model | ||
{ | ||
|
||
protected $guarded = [ | ||
'uuid' | ||
]; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
public $dates = [ | ||
'created_at', | ||
]; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
public $casts = [ | ||
'tags' => 'json' | ||
]; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
public $hidden = [ | ||
'updated_at', | ||
]; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
public $apiMapping = [ | ||
'id' => ['newName' => 'id', 'dataType' => 'int'], | ||
'title' => ['newName' => 'name', 'dataType' => 'string'], | ||
'desc' => ['newName' => 'desc', 'dataType' => 'string'], | ||
'tags' => ['newName' => 'tags', 'dataType' => 'array'], | ||
'other_tags' => ['newName' => 'otherTags', 'dataType' => 'nullable[array'], | ||
'owner' => ['newName' => 'owner_id', 'dataType' => 'nullable[int'], | ||
'created_at' => ['newName' => 'postedAt', 'dataType' => 'datetime'], | ||
]; | ||
|
||
|
||
} |
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,22 @@ | ||
<?php | ||
|
||
namespace Napp\Core\Api\Tests\Transformers; | ||
|
||
use Napp\Core\Api\Tests\Models\Post; | ||
use Napp\Core\Api\Transformers\ApiTransformer; | ||
|
||
/** | ||
* Class PostTransformer | ||
* @package Napp\Core\Api\Tests\Transformers | ||
*/ | ||
class PostTransformer extends ApiTransformer | ||
{ | ||
protected $strict = false; | ||
/** | ||
* @param Post $post | ||
*/ | ||
public function __construct(Post $post) | ||
{ | ||
$this->setApiMapping($post); | ||
} | ||
} |