0

people! :D

I have an html table with all my records from a database table and I want to specify on the bottom when was the table last updated (from creating, updating or deleting a record in the database table).

Is there a built-in way in Laravel to do exactly that? Many thanks!

Looking forward for your responses. Cheers!

uatar
  • 395
  • 3
  • 10
  • Store it in another table along with type of transaction in same transaction. – Naruto Feb 27 '18 at 02:18
  • No such built-in feature but you can query the information_schema of your databse to find out. – Vinay Feb 27 '18 at 02:28
  • Kindly refer [How can I tell when a MySQL table was last updated?](https://stackoverflow.com/questions/307438/how-can-i-tell-when-a-mysql-table-was-last-updated) Run the query using `DB::select()` – Adlan Arif Zakaria Feb 27 '18 at 02:34

3 Answers3

0

You can query for the most recently updated record and use that as reference:

return DB::table('some_table')->orderBy('updated_at', 'desc')->first();
0

Can you try Laravel model observers - I guess this can help you get your task done.

Check the following links.

  1. Laravel Model Observer
  2. Bosnadev – Code Factory - Laravel: Model Observers
Jigs1212
  • 773
  • 8
  • 20
0

You Can Get Model's last updated record.

$last_updated_record=ModelName::select('updated_at')->orderBy('updated_at', 'desc')->first();

Or using DB Query

$last_updated_record= DB::table('table_name')->select('updated_at')->orderBy('updated_at', 'desc')->first();