Laravel Eloquent; Show the most recent record
<p>I'm building a reporting system, to which I import, on a daily basis, a bunch of files into my database. The issue encountered is I may have duplicate but valid records in my database.</p>

<p>In my database I would have the following, example, data set.</p>

<pre><code>ID        NAME         MATERIAL      PRICE        CREATED_AT
1         Foo          FP1234        3.45         2016-01-01 15:00:00
2         Bar          FP8177        7.21         2016-01-01 15:00:00
3         Foo          FP1234        4.87         2016-01-02 15:00:00
4         Baz          FP1231        3.00         2016-01-02 15:00:00
</code></pre>

<p>I would like to know how I can return the above result set, but exclude <code>row 1</code> <strong>because</strong> it is the same as <code>row 3</code>, and <code>row 3</code> is more recent. Adding on to my reasoning, <code>row 1</code> and <code>3</code> are the same, but since <code>row 3</code> has the more recent <code>created_at</code> timestamp, I would only want to see this.</p>

<p>The tricky thing is I need to be able to paginate on top of this, and using Laravel's Collection method <code>forPage</code> is something I was hoping to avoid.</p>

<p><strong>Edit</strong></p>

<p>I can use the Laravel orderBy and groupBy if running a search with an equal too operand, however I need to account for <strong>like</strong> as well.</p>