Search code examples
mysqllaravellaravel-5rdbms

Laravel how to retrieve the recently uploaded values


I have a database in mysql. I upload a set of data to the database table from a .csv file or .xls file. During retrieval I need to retrieve only the set of values which I have recently uploaded to the table in the database. I should not get all the values which stored in the table.(only values recently uploaded to the table should be retrieved). How can I do that using Laravel?


Solution

  • (1)

    In the table where you store the data from CSV and XML, using a migration, create a flag to mark the records you didn't process yet, e.g. is_processed. Give it the default value of 0.

    (2)

    If you have data you already retrieved (processed), set those to 1, so they don't get processed again. You can do this manually with a query, based on the conditions that make sense in your case.

    (3)

    Then, after you store new data, they will be automatically set to is_processed = 0. This means you can identify them afterwards, like this:

    $unprocessedData = MyModel::where('is_processed', 0)->get();
    

    You can also order them if you need to, but - in general - that's the approach I would take.