-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/upgrade-laravel-10' into 3.x
- Loading branch information
Showing
14 changed files
with
146 additions
and
68 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
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,18 @@ | ||
<?php | ||
|
||
namespace Esensi\Model\Traits; | ||
|
||
trait BackwardCompatibleDatesTrait | ||
{ | ||
|
||
/** | ||
* Get the attributes that should be converted to dates. | ||
* | ||
* @return array | ||
*/ | ||
public function getDates() | ||
{ | ||
$defaults = parent::getDates(); | ||
return array_unique(array_merge($this->dates, $defaults)); | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
namespace Esensi\Model\Traits; | ||
|
||
trait DatesToCastsTrait | ||
{ | ||
/** | ||
* Boot the trait. | ||
* | ||
* @return void | ||
*/ | ||
protected static function bootDatesToCastsTrait() | ||
{ | ||
$events = ['saving', 'retrieved', 'deleting']; | ||
|
||
foreach ($events as $event) { | ||
static::$event(function ($model) { | ||
$model->convertDatesToCasts(); | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Convert $dates to $casts automatically. | ||
* | ||
* @return void | ||
*/ | ||
protected function convertDatesToCasts() | ||
{ | ||
if (property_exists($this, 'dates') && property_exists($this, 'casts')) { | ||
foreach ($this->dates as $dateColumn) { | ||
if (!array_key_exists($dateColumn, $this->casts)) { | ||
$this->casts[$dateColumn] = '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
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.