显示使用M-D-Year查看的日期

时间:2016-08-26 08:10:34

标签: laravel laravel-5.2

我是laravel的新手,关于使用MM-DD-YYYY格式向视图显示日期

@extends('layouts.common')
@section('title' ,'Administrator | Category')
@section('contents')
<div class="row">
    <div class="col-md-8 col-md-offset-2">
        <div class="panel panel-default">
            <div class="panel-heading">All Categories</div>
            <div class="panel-body">
                <table class="table">
                    <thead class="thead-inverse">
                        <tr>
                            <th>Category Name</th>
                            <th>Published At</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($categories as $category)
                        <tr>
                            <td><a href="{{ url('/category', $category->id) }}"> {{
                                    $category->name }}</a></td>
                            <td>{{$category->published_at }}</td>
                            <td><a href="{{ route('category.edit',$category->id) }}"><i
                                    class="icon fa fa-edit"></i>&nbsp&nbsp&nbsp</a><i
                                class="icon fa fa-times"></i></td>
                        </tr>
                    </tbody>
                    @endforeach
                </table>
            </div>
        </div>
    </div>
</div>
@endsection @section('js') {!!Html::script('assets/js/jquery.min.js')!!}
{!!Html::script('assets/js/bootstrap.min.js') !!} @endsection

关于我希望将{{$ category-&gt; published_at}}数据显示在该格式中。请帮助谢谢

3 个答案:

答案 0 :(得分:0)

请按照以下方式

{!! date('d-m-Y', strtotime($model->start_date)) !!}
or
{{ date('d-m-Y', strtotime($model->start_date)) }}

我希望帮助你!

答案 1 :(得分:0)

Category模型中

public $dates = ['published_at'];

然后在视图中您可以使用

$category->published_at->format('m-d-Y')

进一步阅读:Eloquent: Mutators

答案 2 :(得分:0)

另一种方法。扩展 Skysplit 回答

在类别模型中

public function getPublishedAtAttribute(){
    return $this->attributes['published_at']->format('m-d-Y');
}

再也不用担心published_at了。的

$category->published_at