Skip to content

Commit

Permalink
Merge pull request #69 from askdkc/main
Browse files Browse the repository at this point in the history
Fix for publishing view files that has its custom namespace
  • Loading branch information
freekmurze authored Oct 11, 2022
2 parents 11cdf05 + 4d54020 commit c377cc7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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;
}
}
Original file line number Diff line number Diff line change
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'));
}
}

0 comments on commit c377cc7

Please sign in to comment.