Vladimir Djukic
Vladimir Djukic

Reputation: 2072

Find last created record by date Laravel 5

How can I find when user last time added record and take that record?

Something like this:

Comment::where('user_id',Auth::id())->where(HERE I NEED TO GET BIGEST create_at)->first();

Any solution for this?

Upvotes: 0

Views: 1405

Answers (1)

Robin Drost
Robin Drost

Reputation: 507

Use the orderby statement:

Comment::where('user_id', Auth::id())->orderBy('created_at', 'desc')->first();

See: http://laravel.com/docs/5.1/queries#ordering-grouping-limit-and-offset

For more info.

Upvotes: 3

Related Questions