Nicksxs

112 经验值

首先在Article.php中已经将published_at设置成Carbon对象了,

public function setPublishedAtAttribute($date)
    {
        $this->attributes['published_at'] = Carbon::createFromFormat('Y-m-d', $date);
    }

但是在ArticlesController中的index方法渲染view时,即显示主页面提示

Call to a member function diffForHumans() on a non-object

错误,index.blade.php中ul一块的代码是直接拷贝博客(手写了怕没找到错误)

@extends('app')
@foreach($articles as $article)
 <article class="format-image group">
  <h2 class="post-title pad">
   <a href="/articles/{{ $article->id }}"> {{ $article->title }}</a>
  </h2>
  <ul class="post-meta pad group">
   <li><i class="fa fa-clock-o"></i>{{ $article->published_at->diffForHumans() }}</li>
   @if($article->tags)
    @foreach($article->tags as $tag)
     <li><i class="fa fa-tag"></i>{{ $tag->name }}</li>
    @endforeach
   @endif
  </ul>
  <div class="post-inner">
   <div class="post-deco">
    <div class="hex hex-small">
     <div class="hex-inner"><i class="fa"></i></div>
     <div class="corner-1"></div>
     <div class="corner-2"></div>
    </div>
   </div>
   <div class="post-content pad">
    <div class="entry custome">
     {{ $article->intro }}
    </div>
    <a class="more-link-custom" href="/articles/{{ $article->id }}"><span><i>更多</i></span></a>
   </div>
  </div>
 </article>
@endforeach

求大大帮助!

昨天在本地按照博客上laravel教程做到第六篇,然后就把代码推到阿里云上了,一开始提示错误是

>PDOException "could not find driver"  

然后我用apt-get install php5-mysql重新安装了下变成了下面这个错误

>PDOException in Connector.php line 55:
SQLSTATE[28000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)  

但是在config/database.php里我的配置是这样的
图片
用的是阿里云的rds,请大神指教!