0

So i have this in my controller

public function index()
{
    $posts = Post::where('reviewed', '=' , 1)->orderBy('created_at', 'DESC');
    $url = asset('img/logo.gif');
    $mytime = Carbon\Carbon::now();
    $this->layout->content = View::make('partials.index', array('posts' => $posts->paginate(9)))->with('img', $url)->with('date' , $mytime);
}

What i want to happen is i want to sort out my post by created_at time stamp but i dont know how to do this properly and this line in $post var ->orderBy('created_at', 'DESC') doesn't seem to work.

so how can i do this properly?

1
  • have you seen the return of the posts variable Commented Feb 25, 2015 at 5:36

2 Answers 2

1

Try this..

 $posts = Post::orderBy('created_at', 'desc')->where('reviewed', '=' , 1)->get();
Sign up to request clarification or add additional context in comments.

2 Comments

i have add my answer please check it and let me know
actually my code was working but anyway thanks for helping :) appreciate it much thanks
0

I think you forgot to chain the get() method, as stated by Deena.

$posts = Post::where('reviewed', '=' , 1)->orderBy('created_at', 'desc')->get()

Could you please dump your $posts variable and show the result ?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.