date_format()要求参数1为DateTimeInterface,给定为空(视图:/home/vagrant/code/blog/resources/views/singlePost.blade.php)

date_format()要求参数1为DateTimeInterface,给定为空(视图:/home/vagrant/code/blog/resources/views/singlePost.blade.php),php,laravel,Php,Laravel,我找不到我的代码有什么问题。我已经试着看了整个代码,但我不能把手指放在上面。如果有人指出我的错误,那将非常有帮助。意思是日期有问题,但我看不出我打错了什么 @extends('layouts.master') @section('content') <!-- Page Header --> <header class="masthead" style="background-image: url('{{asset('assets/img/post-bg.jpg

我找不到我的代码有什么问题。我已经试着看了整个代码,但我不能把手指放在上面。如果有人指出我的错误,那将非常有帮助。意思是日期有问题,但我看不出我打错了什么

@extends('layouts.master')
@section('content')

    <!-- Page Header -->
    <header class="masthead" style="background-image: url('{{asset('assets/img/post-bg.jpg')}}')">
      <div class="overlay"></div>
      <div class="container">
        <div class="row">
          <div class="col-lg-8 col-md-10 mx-auto">
            <div class="post-heading">
              <h1>{{$post->title}}</h1>
              <span class="meta">Posted by
                <a href="#">{{$post->user->name}}</a>
                on {{date_format($post->created_at,'F d,Y')}}</span>
            </div>
          </div>
        </div>
      </div>
    </header>

    <!-- Post Content -->
    <article>
      <div class="container">
        <div class="row">
          <div class="col-lg-8 col-md-10 mx-auto">
            {!!nl2br($post->content)!!}
          </div>
        </div>
<div class="comments">
  <hr>
  <h2>Comments</h2>
  <hr>
  @foreach($post->comments as $comment)
  <p>{{$comment->content}} <br>
  <p><small>by {{$comment->user->name}}, on {{date_format($comment->created_at,'F d,Y')}}</small></p>
  <hr>
  @endforeach

@if(Auth::check())
<form action="{{route('newComment')}}" method="POST">
  @csrf
  <div class="form-group">
<textarea class="form-control" placeholder="Comment..." name="comment" id="" cols="30" rows="4"></textarea>
<input type="hidden" name="post" value="{{$post->id}}">
</div>
<div class="form-group">
  <button class ="btn btn-primary" type="submit">Make Comment</button>
</div>
</form>
@endif

</div>
</article>
    @endsection


comments.blade.php code
@extends('layouts.master'))
@节(“内容”)
{{$post->title}
邮寄人
在{{date_格式($post->created_at,'fd,Y')}上
{!!nl2br($post->content)!!}

评论
@foreach($post->comments as$comment) {{$comment->content}}
通过{{$comment->user->name},在{{date_格式($comment->created_at,'fd,Y')}上


@endforeach @if(Auth::check()) @csrf 评论 @恩迪夫 @端部 comments.blade.php代码
错误显示您必须具有
DateTime
对象

  $created_at = new DateTime("2018-02-01");
  echo date_format($created_at,'F d,Y');

如果您只有日期,如
2018-02-01
,则可以使用简单的
date()
函数

$created_at = "2018-02-01";
echo date('F d,Y',strtotime($created_at));

你也可以通过

echo (new DateTime("2018-02-01"))->format('F d,Y');

感谢这是一个古老的主题,但这条主题是在我搜索解决方案时出现的,我的主题是在从我的数据库中读取时出现的:

$evdate = DateTime::createFromFormat('Y-m-d H:i:s', $row['when']);
然后,此选项将在页面中显示日期,不会出现错误:

<?php echo($evdate->format("H:i d/m/y")) ?>


希望这能帮助其他人,我使用的是
date\u格式
,虽然它在屏幕上正确地工作和显示,但抛出了一个错误,我想从我的日志中消除它。(大概做对了会比一个看起来有效的博奇更好)。

请在这里添加代码而不是图片?事实上,高功率照相机无法正确地看到这个共享图像。我在上面添加了代码,以便共享
$post->created_at
>的任何示例数据?可能重复,但日期不是手动输入的,它们连接到数据库
(new DateTime($comment->created_at))->格式('fd,Y')
日期('fd,Y',strottime($comment->created_at))@C2486
https://stackoverflow.com/questions/50040436/laravel-how-can-i-validate-reset-password-table-token-and-request-token
请帮我解决这个问题。!!