Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to use the Carbon on Views I'm including it on the top of the views file but it doesnt work, I'm doing it like this.

 <?php use carbon/carbon;?>
 @extends('main_layout')

      @foreach ($myquery as $mytask) 
                <tr>

                <td >
                 {{($mytask->firstname)}}
                </td>

                 <td >
                        {{($mytask->lastname)}}
                </td>
                    <td>
               {{($mytask->logon)}}
                    </td>

 @section('content')
 @stop

I just get errors. I want to convert the {{($mytask->logon)}} to human readable format using carbon

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
342 views
Welcome To Ask or Share your Answers For Others

1 Answer

I would add sommething quoting Laravel Documentation for googlers to add how you can transform your SQL datetime fields into Carbon objects:

In your Model:

protected $dates = ['created_at', 'updated_at', 'disabled_at','mydate'];

All the fields present on this array will be automatically accessible in your views with Carbon functions like:

{{ $article->mydate->diffForHumans() }}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...