Search code examples
mysqllaravelchecksum

Get table checksum in Laravel 5.4


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?


Solution

  • 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.