This repository has been archived by the owner on Feb 17, 2022. It is now read-only.
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 #21 from DarkGhostHunter/master
Minor rework with breaking changes
- Loading branch information
Showing
10 changed files
with
182 additions
and
379 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace DarkGhostHunter\Lararut\Casts; | ||
|
||
use DarkGhostHunter\RutUtils\Rut; | ||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes; | ||
|
||
class CastRut implements CastsAttributes | ||
{ | ||
/** | ||
* Transform the attribute from the underlying model values. | ||
* | ||
* @param \Illuminate\Database\Eloquent\Model $model | ||
* @param string $key | ||
* @param mixed $value | ||
* @param array $attributes | ||
* | ||
* @return mixed | ||
*/ | ||
public function get($model, string $key, $value, array $attributes) | ||
{ | ||
return Rut::make($attributes[$model->getRutNumColumn()], $attributes[$model->getRutVdColumn()]); | ||
} | ||
|
||
/** | ||
* Transform the attribute to its underlying model values. | ||
* | ||
* @param \Illuminate\Database\Eloquent\Model $model | ||
* @param string $key | ||
* @param mixed $value | ||
* @param array $attributes | ||
* | ||
* @return mixed | ||
*/ | ||
public function set($model, string $key, $value, array $attributes) | ||
{ | ||
if (!$value instanceof Rut) { | ||
$value = Rut::make($value); | ||
} | ||
|
||
$attributes[$model->getRutNumColumn()] = $value->num; | ||
$attributes[$model->getRutVdColumn()] = $value->vd; | ||
|
||
return $attributes; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.