Thursday, 8 June 2017

Topic 20 - Applying Carbon (DateTime)

Carbon is a package helper that help developers to write and manage logic date inside controller and model . It also helps to manipulate by adding and substracting date from insert date.

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