Example of use :
Model :
public function getDueDateAttribute() { return Carbon::parse($this->check_out)->addDays(7); } public function getDiffDaysAttribute() { return $this->DueDate->diffInDays(Carbon::now()); }
Inside the accessor method , field check_out are being called and manipulate by Carbon class. The first function are to return due date of the book which is within next 7 days. While the second function is to count the different days between current day and the due date should be submitted.
More in carbon , check this link.
References
https://scotch.io/tutorials/easier-datetime-in-laravel-and-php-with-carbon
No comments:
Post a Comment