Here's one simple example. It uses a public method on the model to set a timestamp based on text values.
The model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Mydate extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'dates';
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['created_at', 'updated_at', 'test'];
public function setDate($date, $time)
{
$this->test = strtotime("$date $time");
}
}
A simple use case:
>>> $date = date('Y-m-d')
=> "2016-05-19"
>>> $time = date('H:i')
=> "20:35"
>>>
>>> $mydate = new App\Mydate
=> App\Mydate {#682}
>>>
>>> $mydate->setDate($date, $time)
=> null
>>>
>>> $mydate->test
=> Carbon\Carbon {#681
+"date": "2016-05-19 20:35:00",
+"timezone_type": 3,
+"timezone": "UTC",
}
>>>
>>> $mydate->save()
=> true
>>>
>>> App\Mydate::first()->test->toDateTimeString()
=> "2016-05-19 20:35:00"
>>>
>>> App\Mydate::first()->test
=> Carbon\Carbon {#696
+"date": "2016-05-19 20:35:00",
+"timezone_type": 3,
+"timezone": "UTC",
}
You'd need to work out a few details like validation and such. This is just a simple example to get you started.