定制 vicgutt/laravel-models-finder 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vicgutt/laravel-models-finder

最新稳定版本:v0.1.1

Composer 安装命令:

composer require vicgutt/laravel-models-finder

包简介

Find all models in your Laravel app or package

README 文档

README

GitHub Tests Action Status GitHub PHPStan Action Status GitHub Code Style Action Status Latest Version on Packagist Total Downloads

This package allows you to find and retrieve all Laravel models in a given folder. A "model" is any class extending Illuminate\Database\Eloquent\Model.

Here's a quick example:

// 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',
    ],
]

Installation

You can install the package via composer:

composer require vicgutt/laravel-models-finder

Usage

You can initiate the discovery of models by using the find static method.

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

This method accepts 3 optional arguments:

  • directory: The directory in which to recusively start searching for models. Defaults to app_path('Models').
  • basePath: The autoloaded entry directory of the project where the search will be initiated. Defaults to base_path().
  • baseNamespace: The autoloaded base namespace of the project where the search will be initiated. Defaults to ''.

The basePath & baseNamespace properties will most likely correspond to an autoloaded entry in a composer.json file. Example:

{
    "autoload": {
        "psr-4": {
            // Base namespace       |  Base path
            "Spatie\\MediaLibrary\\": "src"
        }
    }
}

Here's an example showcasing searching for a model in the vendor folder:

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',
    ],
]

The return value of the method is a lazy collection (Illuminate\Support\LazyCollection).

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

If you're interested in contributing to the project, please read our contributing docs before submitting a pull request.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 1.47k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固