The issue is that $modelPath is a string containing the path to the model, not the actual model class. To get the model class, you can use the app() function to resolve the class from the path. Here's an updated version of the parseNameAndPath() method:
private function parseNameAndPath(string $model): array
{
$localParts = explode('\', $model);
$modelPath = '\' . ucfirst($localParts[(count($localParts) - 1)]);
$modelName = basename($modelPath, '.php');
$modelInitials = $this->modelInitials($modelName);
$modelClass = app()->getNamespace() . 'Models' . str_replace('/', '\', dirname($modelPath)) . '\' . $modelName;
$rowCount = $modelClass::get()->count();
return [
'name' => $modelName,
'initials' => $modelInitials,
'path' => $modelPath,
'rowCount' => $rowCount,
];
}
This code uses the app()->getNamespace() method to get the namespace of the application, and then constructs the full class name by appending the namespace, the Models directory, the directory path of the model, and the model name. The str_replace() function is used to convert the forward slashes in the path to backslashes, which is the namespace separator in PHP.
Note that this assumes that all models are located in the app/Models directory. If your models are located in a different directory, you'll need to adjust the code accordingly.