Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for publishing view files that has its custom namespace #69

Merged
merged 4 commits into from Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -158,6 +158,14 @@ command:
php artisan vendor:publish --tag=your-package-name-views
```

> **Note:**
>
> If you use custom view namespace then you should change your publish command like this:
```bash
php artisan vendor:publish --tag=custom-view-namespace-views
```


### Sharing global data with views

You can share data with all views using the `sharesDataWithAllViews` method. This will make the shared variable
Expand Down
9 changes: 7 additions & 2 deletions src/PackageServiceProvider.php
Expand Up @@ -64,8 +64,8 @@ public function boot()

if ($this->package->hasViews) {
$this->publishes([
$this->package->basePath('/../resources/views') => base_path("resources/views/vendor/{$this->package->shortName()}"),
], "{$this->package->shortName()}-views");
$this->package->basePath('/../resources/views') => base_path("resources/views/vendor/{$this->packageView($this->package->viewNamespace)}"),
], "{$this->packageView($this->package->viewNamespace)}-views");
}

$now = Carbon::now();
Expand Down Expand Up @@ -195,4 +195,9 @@ protected function getPackageBaseDir(): string

return dirname($reflector->getFileName());
}

public function packageView(?string $namespace)
{
return is_null($namespace) ? $this->package->shortName() : $this->package->viewNamespace;
}
}
Expand Up @@ -25,9 +25,9 @@ public function it_can_load_the_views_with_a_custom_namespace()
public function it_can_publish_the_views_with_a_custom_namespace()
{
$this
->artisan('vendor:publish --tag=package-tools-views')
->artisan('vendor:publish --tag=custom-namespace-views')
->assertExitCode(0);

$this->assertFileExists(base_path('resources/views/vendor/package-tools/test.blade.php'));
$this->assertFileExists(base_path('resources/views/vendor/custom-namespace/test.blade.php'));
}
}