Skip to content

How do I get the path to all Models in all Modules #1987

Answered by dcblogdev
jcc5018 asked this question in Q&A
Discussion options

You must be logged in to vote

Slightly better version

$modules = Module::allEnabled();
$models = [];
$modulesDirectoryName = basename(config('modules.paths.modules')); // Compute once

foreach ($modules as $module) {
    $modelsPath = Module::getModulePath($module->getName()) . config('modules.paths.generator.model.path');

    if (!File::exists($modelsPath)) {
        continue; // Skip if the directory doesn't exist
    }

    // Scan for all PHP files in the Models directory
    $files = File::glob("{$modelsPath}/*.php");

    foreach ($files as $file) {
        $relativePath = substr($file, strpos($file, $modulesDirectoryName));
        $filename = basename($file); // Extract the filename

        // Add model with…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by dcblogdev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants