p4scu41/basecrudapi

提供RESTful API的基础类。

1.0.2 2018-06-01 20:06 UTC

This package is not auto-updated.

Last update: 2024-09-29 06:02:31 UTC


README

提供RESTful API的基础类。

安装

通过composer安装

composer require p4scu41/basecrudapi

注册服务提供者

注意!如果您使用laravel>=5.5并启用包自动发现功能,以下步骤是可选的。

将服务提供者添加到 config/app.php 中的 providers 部分

p4scu41\BaseCRUDApi\BaseCRUDApiServiceProvider::class,

发布配置文件

php artisan vendor:publish --provider="p4scu41\BaseCRUDApi\BaseCRUDApiServiceProvider" --tag="config"

配置供应商

* Laravel Activitylog [https://github.com/spatie/laravel-activitylog]
    - php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider"
    - Take a look at config/activitylog.php before run migration
    - php artisan migrate
    - Add in .env ACTIVITY_LOGGER_ENABLED=true
* Laravel 5 Repositories [https://github.com/andersao/l5-repository]
    - In your config/app.php add Prettus\Repository\Providers\RepositoryServiceProvider::class to the end of the providers array
    - php artisan vendor:publish --provider "Prettus\Repository\Providers\RepositoryServiceProvider"
    - Take a look at config/repository.php
* PHP Performance tool [https://github.com/bvanhoekelen/performance]
    - In app/Http/Kernel.php add \p4scu41\BaseCRUDApi\Http\Middleware\PerformanceLoggerFinish::class, at the end of the $middleware array
    - You can handle the performance logger in the controller with is_tracking_performance = true, you can add exceptions with except_track_performance array and enable the queries log with is_query_log = true
* LERN (Laravel Exception Recorder and Notifier) [https://github.com/tylercd100/lern#lern-laravel-exception-recorder-and-notifier]
    - php artisan vendor:publish --provider="Tylercd100\LERN\LERNServiceProvider"
    - Take a look at config/lern.php before run migration
    - php artisan migrate
* Laravel Stats Tracker [https://github.com/antonioribeiro/tracker]
    - In your config/app.php add PragmaRX\Tracker\Vendor\Laravel\ServiceProvider::class to the end of the providers array
    - php artisan vendor:publish --provider=PragmaRX\\Tracker\\Vendor\\Laravel\\ServiceProvider
    - By default everything is disabled you need to decide what you want to log. Take a look at config/tracker.php and eneable some options:
    ```php
        'enabled' => true,
        'use_middleware' => true,
        'do_not_track_paths' => [
            // 'api/*',
        ],
        'do_not_track_ips' => [
            '127.0.0.0/24', // Local: range 127.0.0.1 - 127.0.0.255
            '192.168.0.0/24', // Megacable
            '192.168.1.0/24', // Infinitum
        ],
        'log_untrackable_sessions' => false,
        'log_enabled' => true,
        'console_log_enabled' => true,
        'geoip_database_path' => storage_path('geoip'),
        'log_geoip' => true,
        'log_user_agents' => true,
        'log_users' => true,
        'log_devices' => true,
        'log_languages' => true,
        'log_referers' => true,
        'log_paths' => true,
        'log_queries' => true,
        'log_routes' => true,
        'user_model' => p4scu41\BaseCRUDApi\Models\User::class,
        'stats_panel_enabled' => true,
    ```
    - Add \PragmaRX\Tracker\Vendor\Laravel\Middlewares\Tracker::class to the array $middleware in app/Http/Kernel.php
    - Create a database connection called tracker in config/database.php
    - php artisan tracker:tables
    - php artisan migrate
    - composer require geoip2/geoip2
    - php artisan tracker:updategeoip
    - sudo chmod -R 777 storage/geoip/
    - git clone https://github.com/BlackrockDigital/startbootstrap-sb-admin-2.git public/templates/sb-admin-2
    - cd public/templates/sb-admin-2
    - git checkout tags/v3.3.7+1
    - git checkout -b v3.3.7+1
    - sudo npm install -g bower
    - bower install
    - sudo npm install --global gulp-cli
    - gulp
* CORS Middleware for Laravel 5 [https://github.com/barryvdh/laravel-cors]
* JSON Web Token Authentication for Laravel & Lumen [https://github.com/tymondesigns/jwt-auth]
    - In your app/Http/Kernel.php add 'jwt.validation' => \p4scu41\BaseCRUDApi\Http\Middleware\JWTAuthValidation::class to the end of the routeMiddleware array

配置

在您的 config/app.php 中,将 p4scu41\BaseCRUDApi\Providers\ResponseMacroServiceProvider::class 添加到 providers 数组的末尾

如果您想添加JWT集成,请将目录config中所有对User模型的引用更改为 p4scu41\BaseCRUDApi\Models\User::class

使用方法

请修改我

测试

$ composer test

安全

如果您发现任何安全相关的问题,请通过电子邮件 pasperezn@gmail.com 联系,而不是使用问题跟踪器。