PHP code example of maartenpaauw / laravel-date-time-zone-cast
1. Go to this page and download the library: Download maartenpaauw/laravel-date-time-zone-cast library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
maartenpaauw / laravel-date-time-zone-cast example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Maartenpaauw\LaravelDateTimeZoneCast\DateTimeZoneCast;
class User extends Model
{
protected $casts = [
'timezone' => DateTimeZoneCast::class,
];
}
Schema::table('users', function (Blueprint $table) {
$table->string('timezone')->nullable();
});
$user = new User();
$user->timezone = 'Europe/Amsterdam';
$user->save();
$timezone = $user->timezone; // DateTimeZone instance
echo $timezone->getName(); // 'Europe/Amsterdam'