PHP code example of lazywe / lazy-admin

1. Go to this page and download the library: Download lazywe/lazy-admin 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/ */

    

lazywe / lazy-admin example snippets



    //... 

    /**
     * Define the routes for the application.
     */
    public function map()
    {
        //...
        //加载后台权限组
        $this->mapAdminRoutes();
    }
    
    /**
     * 加载后台权限组
     */
    protected function mapAdminRoutes()
    {
        Route::prefix(config('lazy-admin.prefix'))
            ->middleware('web', 'lazy-admin')
            ->namespace(sprintf("%s\Admin", $this->namespace)) 
            ->group(function ($router) {
                // 后台路由文件在routes下的admin目录下 路由文件分组
                foreach (glob(base_path('routes/admin') . '/*.php') as $file) {
                    $router->group([], $file);
                }
            });
    }

    // ...


    // 控制角色 多个 |隔开
    Route::group(['middleware' => ['role:administrator']], function () {
        //...
    });

    // 控制权限 多个 |隔开
    Route::group(['middleware' => ['permission:user-create']], function () {
        //...
    });
    // 控制角色 多个|隔开 + 控制权限 多个|隔开
    Route::group(['middleware' => ['role:administrator','permission:user-create']], function () {
        // ...
    });
    // 控制角色 或者 控制权限 多个|隔开
    Route::group(['middleware' => ['role_or_permission:administrator|user-create']], function () {
        //...
    });

    @lazy_can('user-create')
        // ...
    @else_lazy_can('user-all-create')
        // ...
    @end_lazy_can

    @lazy_role('administrator')
        // ...
    @else_lazy_role('editor')
        // ...
    @else_lazy_role

    @lazy_hasanyrole('administrator|editor')
        // ...
    @else
        // ...
    @end_lazy_hasanyrole

    @lazy_hasallroles('administrator|editor')
        // ...
    @else
        // ...
    @end_lazy_hasallroles

    @lazy_unlessrole('administrator')
        // ...
    @else
        // ...
    @end_lazy_unlessrole

    // layout
    @extends('lazy-view::layout')
    @section('content')
    // ... 自定义html
    @endsection

    // css stack
    @push('css')
        // ... css
    @endpush

    // js stack
    @push('scripts')
        // ... 自定义
    @endpush