src/LikeCounter.php
public static function rebuild($modelClass)
	{
		if(empty($modelClass)) {
			throw new \Exception('$modelClass cannot be empty/null. Maybe set the $morphClass variable on your model.');
		}
		
		$builder = Like::query()
			->select(\DB::raw('count(*) as count, likeable_type, likeable_id'))
			->where('likeable_type', $modelClass)
			->groupBy('likeable_id');
		
		$results = $builder->get();
		
		$inserts = $results->toArray();
		
		\DB::table((new static)->table)->insert($inserts);
	}
public static function rebuild($modelClass)
	{
		if(empty($modelClass)) {
			throw new \Exception('$modelClass cannot be empty/null. Maybe set the $morphClass variable on your model.');
		}
		
		$builder = Like::query()
			->select(\DB::raw('count(*) as count, likeable_type, likeable_id'))
			->where('likeable_type', $modelClass)
			->groupBy('likeable_id');
		
		$results = $builder->get();
		
		$inserts = $results->toArray();
		
		\DB::table((new static)->table)->insert($inserts);
	}
public static function rebuild ( $ modelClass ) { if ( empty ( $ modelClass ) ) { throw new \ Exception ( '$modelClass cannot be empty/null. Maybe set the $morphClass variable on your model.' ) ; } $ builder = Like :: query ( ) -> select ( \ DB :: raw ( 'count(*) as count, likeable_type, likeable_id' ) ) -> where ( 'likeable_type' , $ modelClass ) -> groupBy ( 'likeable_id' ) ; $ results = $ builder -> get ( ) ; $ inserts = $ results -> toArray ( ) ; \ DB :: table ( ( new static ) -> table ) -> insert ( $ inserts ) ; }
Delete all counts of the given model, and recount them and insert new counts

@param string $model (should match Model::$morphClass)
Delete all counts of the given model and recount them and insert new counts