0

What do you use to get the checksum of a table in Laravel? Is there something already abstracted for this or you have to use raw commands?

ali
  • 10,927
  • 20
  • 89
  • 138

1 Answers1

2

You have to use raw commands, but it is pretty easy, just add this method to your model:

public static function checksum()
{
    $tableName = with(new static)->getTable();
    $query = sprintf('CHECKSUM TABLE %s', $tableName);

    return \DB::select(\DB::raw($query))[0]->Checksum;
}

You can now call this method statically to get the checksum.

Jan Wytze
  • 3,307
  • 5
  • 31
  • 51