Laravel Nova-将工具更改为资源工具

时间:2019-05-22 10:37:12

标签: laravel laravel-nova

我正在尝试将构建Nova工具转换为资源工具。我试图将我的工具更改为扩展ResourceTool而不是Tool,并将资源工具添加到字段中的Resource上,但未显示。我还更改了ToolServiceProvider的代码以匹配ResourceTool的代码,但不幸的是它无法正常工作。

我已经搜索过互联网,但我似乎是唯一遇到此问题的人,任何人都经历过此事并且知道该怎么办?我没有收到任何错误消息,资源工具只是没有显示。

这是我的代码,出于可读性和机密性,我删除了其中的一些代码。

产品(资源)

<?php

namespace App\Nova;

use confidentiality\SalesHistory\SalesHistory;

class Product extends Resource
{
    /**
     * Get the fields displayed by the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),

            SalesHistory::make(),

        ];
    }
}

SalesHistory (资源工具)

<?php

namespace confidentiality\SalesHistory;

use Laravel\Nova\ResourceTool;

class SalesHistory extends ResourceTool
{
    /**
     * Get the displayable name of the resource tool.
     *
     * @return string
     */
    public function name()
    {
        return 'Sales History';
    }

    /**
     * Get the component name for the resource tool.
     *
     * @return string
     */
    public function component()
    {
        return 'sales-history';
    }
}

ToolServiceProvider (资源工具)

<?php

namespace confidentiality\SalesHistory;

use Laravel\Nova\Nova;
use Laravel\Nova\Events\ServingNova;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;

class ToolServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        $this->app->booted(function () {
            $this->routes();
        });

        Nova::serving(function (ServingNova $event) {
            Nova::script('sales-history', __DIR__.'/../dist/js/tool.js');
            Nova::style('sales-history', __DIR__.'/../dist/css/tool.css');
        });
    }

    /**
     * Register the tool's routes.
     *
     * @return void
     */
    protected function routes()
    {
        if ($this->app->routesAreCached()) {
            return;
        }

        Route::middleware(['nova'])
                ->prefix('nova-vendor/sales-history')
                ->group(__DIR__.'/../routes/api.php');
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

2 个答案:

答案 0 :(得分:0)

我终于解决了。我还必须更改tool.js文件以匹配资源工具的文件。

Nova.booting((Vue, router, store) => {
    Vue.component('sales-history', require('./components/Tool'))
})

答案 1 :(得分:0)

从项目的根目录尝试此命令:

composer update