Hello everyone,
I am following the tutorials from laravel and I am trying to switch between 2 functions that I want to call.
one is for when a page needs to be shows tomorrow for example. ( then I want to do : Carbon::parse ).
And one if a page needs to be shown today and then I would do : Carbon::now().
Here is my code :
/**
* setPublishedAtAttributes
* @param $data
* @return void
*/
public function setPublishedAtAttribute($date)
{
if($date !== Carbon::now()->toDateString()) {
$this->attributes['published_at'] = Carbon::parse($date);
}
$this->attributes['published_at'] = Carbon::createFromFormat('Y-m-d', $date);
}
How can I achieve this properly.