Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

In Laravel models, what is const DATE_FORMAT = 'l jS \\of M \\@ Y g:i a';???

I found in github and I was trying to find out what it is mean const DATE_FORMAT = 'l jS \of M \@ Y g:i a'; ?

class Post extends BaseModel 
{   
    const DATE_FORMAT = 'l jS \\of M \\@ Y g:i a';
    public static $rules = array(
        'title' => 'required | max:255',
        'content' => 'required'

        );
use Carbon\Carbon;

class BaseModel extends Eloquent
{
    //All accessors start with the word get and use camelCase
    //these are also getters
    public function getCreatedAtAttribute($value)
    {
        //this is going into the carbon framework and creting an instance
        $utc = Carbon::createFromFormat($this->getDateFormat(), $value);

        return $utc->setTimezone('America/Chicago');
    }

    public function getUpdatedAtAttribute($value)
    {

        $utc = Carbon::createFromFormat($this->getDateFormat(), $value);

        return $utc->setTimezone('America/Chicago');
    }

there is no way to find in laravel.com Model

would be more easier for us if we put {{($comment->user->created_at)}} it will create for us 2014-10-15 08:15:00? How would do Tuesday 29th of Nov @ -0001 6:00 pm? just put like {{{ $post->created_at->format(Post::DATE_FORMAT)}}}? I have no idea how able to put the today of week and the date of month. what I have found a link http://laravel.com/docs/4.2/schema#adding-columns Do you have more information for DATE_FORMAT?

1 Answer

Hi Brian,

Laravel dates are already instances of Carbon.

So if you want the output to be something like that (Jun 26, 2014) you can simply do this

{{ $video->created_at->toFormattedDateString() }}

Check out the docs if you need more customization https://github.com/briannesbitt/Carbon