如何从 Laravel 包访问视图

问题描述 投票:0回答:1

我正在开发一个自定义包来管理我的团队项目的许可,我现在面临的问题是通过路由器访问 LicenseExpired 视图,其他一切都正常。

这是包结构:

您可以在 GitHub 上查看更多信息:GitHub 存储库

以下是

Routes/index.php
的内容:

Route::get('/activate-product', function () {
    return view('LicenseExpired');
})->name('license');

Route::post('/activate-product', [Index::class, 'webStore'])->name('license.store');

Route::post('api/license', [Index::class, 'store']);

LicenseServiceProvider
的内容:

 public function boot()
    {
        // Load migrations
        $this->loadMigrationsFrom(__DIR__.'/Migrations');

        // Load views
        $this->loadViewsFrom(__DIR__.'/Views', 'Lamine/License');

        // Load Routes
        $this->loadRoutesFrom(__DIR__ . '/Routes/index.php');

        $this->publishes([
            __DIR__.'/Migrations' => database_path('migrations'),
        ], 'migrations');

        // publish routes
        $this->publishes([
            __DIR__.'/Routes/index.php' => base_path('routes/license.php'),
        ], 'routes');

        // publish views
        $this->publishes([
            __DIR__.'/Views' => resource_path('views'),
        ], 'views');
    }
php laravel package laravel-blade packagist
1个回答
0
投票

您的包的目录结构不遵循约定。视图应该位于项目根目录的

resources/views
文件夹中。在服务提供商的
boot()
方法中,您应该执行以下操作:

public function boot(): void
{
    $this->loadViewsFrom(__DIR__ . '/../resources/views', 'license');
}

然后您可以通过命名空间来使用包中的视图

license
:

Route::get('/activate-product', function () {
    return view('license::LicenseExpired');
})->name('license');
© www.soinside.com 2019 - 2024. All rights reserved.