ianrothmann/inertia-laravel-app-service

RocketFramework Inertia Laravel 辅助工具

3.0 2023-07-07 14:05 UTC

This package is auto-updated.

Last update: 2024-09-07 17:07:49 UTC


README

RocketFramework for Inertia and Laravel.

安装

composer install ianrothmann/inertia-laravel-app-service

在 config/app.php (如果未自动配置)

服务提供者

IanRothmann\InertiaApp\ServiceProviders\InertiaAppServiceProvider::class

外观

'Rocket' =>IanRothmann\InertiaApp\Facades\InertiaApp::class

发布配置

php artisan vendor:publish --provider="IanRothmann\InertiaApp\ServiceProviders\InertiaAppServiceProvider"  --tag="config"

配置

在 AppServiceProvider.php 的 boot 方法中

InertiaApp::register()->resolveMenuItemRightsWith(function($code){
            //The code that is required to resolve a menu right
            return Auth::check() && Auth::user()->hasRight($code);
        });

菜单

菜单可以在中间件中指定,也可以在任何控制器中修改,在传递视图之前。

用法

您可以给菜单一个名称,例如 "main",然后链式添加项目。图标是可选的。如果您需要自定义项目,可以使用 ->custom

 $group=InertiaApp::menuGroup('Sub-menu','mdi-account')
            ->route('Page 1','pages.page1',[],'mdi-phone')
            ->link('Google','http://google.com','mdi-link');

        InertiaApp::menu('main')
            ->route('Item 1','pages.spec',[1,2],'mdi-home')
            ->route('Item 2','pages.spec',[2,1],'mdi-phone','test')
            ->route('Item 3','pages.spec',[9,8],'mdi-phone')
            ->group($group)
            ->link('Google','http://google.com');

前缀

有时可能需要将项目前缀(尤其是在从控制器中修改中间件定义的菜单时。所有项目函数都可以以 prepend 开头以添加前缀。

$group=InertiaApp::menuGroup(Auth::user()->name,'mdi-account')
            ->route('Update profile','pages.user.profile',[],'mdi-account-card-details-outline')
            ->route('Change password','pages.user.changepassword',[],'mdi-key-variant');

        InertiaApp::menu('main')
            ->prependGroup($group); //or prependRoute, prependCustom etc.

辅助函数

为了简洁,我们注册了 iview(),它与 Inertia::render() 相同。您还可以使用 page_title('Page title here',$addTobreadcrumbs=true) 来设置页面标题和面包屑。

前端

文档即将推出

面包屑

文档即将推出