jeudi 29 décembre 2016

How to access a column in laravel query result

I'm getting an error in my controller Undefined property: Illuminate\Database\Eloquent\Collection::$created_at

How can I access a column created_at from a result of laravel query?

Controller Code:

    public function getDashboard() {
        $posts=Post::latest('created_at')->get();
        dd($posts->created_at);
  //      $posts->created_at=Carbon::parse($posts->created_at)->diffForHumans(Carbon::now());
        return view('dashboard',compact('posts'));
    }

It works with findOrFail(some_id) but not with this, why?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2il0KRE
via IFTTT

Aucun commentaire:

Enregistrer un commentaire