Skip to content

Add docs for 'extras' disk and bundling application resources #181

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions resources/views/docs/desktop/1/digging-deeper/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Storage::disk('music')->get('file.txt');
Storage::disk('pictures')->get('file.txt');
Storage::disk('videos')->get('file.txt');
Storage::disk('recent')->get('file.txt');
Storage::disk('extras')->get('file.txt');
```

Note that the PHP process which runs your application operates with the same privileges as the logged-in user, this
Expand Down Expand Up @@ -91,5 +92,52 @@ However, in a NativePHP app, this approach is less applicable. The entire applic

We recommend avoiding symlinks within your NativePHP app. Instead, consider either:

- Placing files directly in their intended locations
- Using Laravel's Storage facade to mount directories outside your application
- Placing files directly in their intended locations
- Using Laravel's Storage facade to mount directories outside your application

## Bundling Application Resources

NativePHP allows you to bundle additional files with your application that can be accessed at runtime. This is useful for including pre-compiled executables or other resources that need to be distributed with your app.

### Adding Files

To include extra files with your application, place them in a `extras/` directory at the root of your Laravel project:

```
your-project/
├── extras/
│ ├── my-tool.sh
│ ├── my-tool.exe
│ └── sample.csv
├── app/
└── ...
```

These files will be automatically bundled with your application during the build process.

The `extras` disk is read-only. Any files you write to this directory will be overwritten when your application is updated.

### Accessing Files

You can access bundled extra files using Laravel's Storage facade with the `extras` disk:

```php
use Illuminate\Support\Facades\Storage;

$toolPath = Storage::disk('extras')->path('my-tool.exe');
```

### Using Bundled Tools

```php
use Illuminate\Support\Facades\Storage;
use Native\Laravel\Facades\ChildProcess;

// Get the path to a bundled executable
$toolPath = Storage::disk('extras')->path('my-tool.sh');

ChildProcess::start(
cmd: $toolPath,
alias: 'my-tool'
);
```