PHP code example of f-oris / laravel-extension

1. Go to this page and download the library: Download f-oris/laravel-extension 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/ */

    

f-oris / laravel-extension example snippets



//...

$app->singleton('router', \Foris\LaExtension\Routing\Router::class);

return $app;


//...
Schema::create('resources', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('desc');
    $table->tinyInteger('status')->default(\Foris\LaExtension\Traits\Models\StatusDefinition::STATUS_ENABLE);
    $table->softDeletes();
    $table->timestamps();
});
//...


//...
class Resource extends Model
{
    protected $guarded = ['id'];
}


//...
Route::apiResource('resource', 'ResourceController');


// ...
use Foris\LaExtension\Traits\Models\StatusOperation;
use Foris\LaExtension\Traits\Models\StatusDefinition;

class Resource extends Model implements StatusDefinition
{
    use StatusOperation;

    protected $guarded = ['id'];
}


//...
use Foris\LaExtension\Traits\Repositories\StatusOperation;

class ResourceRepository extends CrudRepository
{
    use StatusOperation;
    
    //...
}


//...
use Foris\LaExtension\Traits\Services\StatusOperation;

class ResourceService extends CrudService
{
    use StatusOperation
    
    //...
}


//...
use Foris\LaExtension\Traits\Controllers\StatusOperation;

class ResourceController extends Controller
{
    use ResourceOperation, ExtResponse, StatusOperation, SelectOption;
    
    //...
}


return [
    //...
    'resource_route' => [
        /**
         * 默认路由配置
         */
        'default' => [
            /*
            'index' => '查看{resource_name}列表',
            'create' => '查看{resource_name}创建表单',
            'edit' => '查看{resource_name}编辑表单',
            'store' => '创建{resource_name}信息',
            'show' => '查看{resource_name}详情',
            'update' => '更新{resource_name}信息',
            'destroy' => '删除{resource_name}信息',
            */
        ],

        /**
         * 自定义资源通用路由
         */
        'extra' => [
            /*
            'batchDestroy' => [
                'method' => 'delete',
                'route_suffix' => 'delete/batch',
                'name' => '批量删除{resource_name}信息',
            ],
            */
            'enable' => [
                'method' => 'put',
                'route_suffix' => '{resource}/enable',
                'name' => '启用{resource_name}信息',
            ],

            'disable' => [
                'method' => 'put',
                'route_suffix' => '{resource}/disable',
                'name' => '禁用{resource_name}信息',
            ],

            'batchEnable' => [
                'method' => 'put',
                'route_suffix' => 'enable/batch',
                'name' => '批量启用{resource_name}信息',
            ],

            'batchDisable' => [
                'method' => 'put',
                'route_suffix' => 'disable/batch',
                'name' => '批量禁用{resource_name}信息',
            ],
            /*
            'selectOptions' => [
                'method' => 'get',
                'route_suffix' => 'select_options',
                'name' => '查看{resource_name}选项信息',
            ],
            */
            
            // 可根据实际情况增加自定义资源通用路由
        ]
    ]
];
sh
$ php artisan make:model Resource -mr
sh
$ php artisan migrate