使用碳在景观laravel [英] Use carbon on Views laravel

查看:92
本文介绍了使用碳在景观laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在视图中使用Carbon我将其包含在视图文件的顶部,但它不起作用,我正在这样做。

 <?php使用碳/碳;?> 
@extends('main_layout')

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

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

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

@section('content')
@stop

我只是收到错误。我想将{{($ mytask-> logon)}}转换为使用碳的人类可读格式

解决方案

我会添加为Google员工引用 Laravel文档以添加如何将SQL datetime字段转换为Carbon对象: p>

在您的模型中:

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

此数组中存在的所有字段将在您的视图中自动访问,其功能如下: p>

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

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

解决方案

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() }}

这篇关于使用碳在景观laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆