PHP code example of vicgutt / laravel-models-finder

1. Go to this page and download the library: Download vicgutt/laravel-models-finder library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vicgutt / laravel-models-finder example snippets


// On an app containing only the default Laravel "User" model, running:
$models = ModelsFinder::find()
    ->map(static fn (ModelData $model): array => [
        'path' => $model->path,
        'class' => $model->class,
    ])
    ->toArray();

// would return the following:
[
    [
        'path' => '/[...]/my-project/app/Models/User.php',
        'class' => '\App\Models\User',
    ],
]

$models = ModelsFinder::find(
    directory: app_path('Models'),
    basePath: base_path(),
    baseNamespace: '',
);

ModelsFinder::find(
    directory: base_path('vendor/spatie/laravel-medialibrary'),
    basePath: base_path('vendor/spatie/laravel-medialibrary/src'),
    baseNamespace: 'Spatie\MediaLibrary'
)->toArray(),

// would return the following:
[
    [
        'path' => '[...]/vendor/spatie/laravel-medialibrary/src/MediaCollections/Models/Media.php',
        'class' => 'Spatie\MediaLibrary\MediaCollections\Models\Media',
    ],
]