I'm working on a custom package to manage the licensing of my team projects, the problem I'm facing right now is to access the LicenseExpired view through the router, everything else works fine.
Here is the package structure:
You can see more on GitHub: GitHub repo
Here is the content of 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']);
the content of 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');
}
The directory structure for your package does not follow conventions. Views should be in a resources/views
folder in the root of your project. In the boot()
method of your service provider you should then do this:
public function boot(): void
{
$this->loadViewsFrom(__DIR__ . '/../resources/views', 'license');
}
You can then use the views from the package by using the namespace license
:
Route::get('/activate-product', function () {
return view('license::LicenseExpired');
})->name('license');