PHPackages                             gzai/laravel-box-adapter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. gzai/laravel-box-adapter

ActiveLibrary

gzai/laravel-box-adapter
========================

Box.com filesystem adapter with Filament integration

1.0.0(6mo ago)09MITPHPPHP ^8.2

Since Oct 23Pushed 6mo agoCompare

[ Source](https://github.com/gzai/laravel-box-adapter)[ Packagist](https://packagist.org/packages/gzai/laravel-box-adapter)[ RSS](/packages/gzai-laravel-box-adapter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (6)Versions (2)Used By (0)

Laravel Box Adapter
===================

[](#laravel-box-adapter)

Introduction
------------

[](#introduction)

Laravel Box Adapter is a Laravel package for interacting with the Box API.

Features
--------

[](#features)

- Easily access to the Box API for managing files and folders.
- Supports Filament for file upload.

Register Box developer client
=============================

[](#register-box-developer-client)

Box API Reference:

Registering a developer client for the Box API:

Steps:

- Select Custom App
- Step 1 of 2, fill in the app name and purpose input.
- Step 2 of 2, select an authentication method: `User Authentication (OAuth 2.0)`
- After create custom app, go to `Configuration` tab in your platform app.
- Copy `Client ID` &amp; `Client Secret` in `OAuth 2.0 Credentials` section to your `.env` file.
- Add redirect URI for your callback url in `OAuth 2.0 Redirect URIs` section, you can add your callback localhost url.

Requirements
============

[](#requirements)

- PHP: `^8.2`
- Illuminate support: `^11.0`
- Guzzlehttp guzzle: `^7.0`
- League flysystem: `^3.0`
- Ramsey uuid: `^4.0`

This package can also be used with:

- Filament: `^3.0|^4.0`

Installation
============

[](#installation)

Require this package with [Composer](https://getcomposer.org), in the root directory of your project.

```
composer require gzai/laravel-box-adapter

```

Configuration
-------------

[](#configuration)

To publish the config, run the vendor publish command:

```
php artisan vendor:publish --provider="Gzai\LaravelBoxAdapter\BoxAdapterServiceProvider" --tag=laravel-box-adapter-config

```

This will create a new file named `config/box.php`

The `config/box.php` config file contains:

```
return [
    'client_id' => env('BOX_CLIENT_ID'),
    'client_secret' => env('BOX_CLIENT_SECRET'),
    'redirect' => env('BOX_REDIRECT_URI'),
    'authorize_url' => 'https://account.box.com/api/oauth2/authorize',
    'token_url' => 'https://api.box.com/oauth2/token',
    'api_url' => 'https://api.box.com/2.0',
    'upload_url' => 'https://upload.box.com/api/2.0',
    'routes_enabled' => true,
    'user_enabled' => true,
    'redirect_callback' => false,
    'redirect_callback_url' => '',
    'download_folder' => 'box_download',
    'folder' => [
        'parent' => 0,
    ],
];

```

Breaking it down:

- `routes_enabled` to accommodate Authentication Box and get Callback from Box. Set it to `false` if you want to create your own logic.
- `user_enabled` is indicates whether the `token` belongs to a specific user or can be used globally. Set it to `true` for a user-specific token, or `false` for a globally usable token.
- `redirect_callback` to accommodate redirect after the API callback Box, set it to `true` for redirect to a specific url in `redirect_callback_url`.
- `redirect_callback_url` a specific url when you want to redirect after login to Box.
- `download_folder` a specific folder when you want to download a file to your project path.
- `folder` add folders ID of your Box folder. The parent folder is used for the root folder.

Migration
---------

[](#migration)

To publish the migration, run the vendor publish command:

```
php artisan vendor:publish --provider="Gzai\LaravelBoxAdapter\BoxAdapterServiceProvider" --tag=laravel-box-adapter-migrations

```

This will create a new file named `database/migrations/xxxx_xx_xx_xxxxxx_create_box_tokens_table.php`

Run the migration:

```
php artisan migrate

```

.ENV Configuration
------------------

[](#env-configuration)

Add the environment variables to your `.env` file:

```
BOX_CLIENT_ID=[Client ID]
BOX_CLIENT_SECRET=[Client Secret]
BOX_REDIRECT_URI=http://localhost:9000/box/callback

```

Please adjust with your client id, client secret and redirect url.

Usage
=====

[](#usage)

If your config box `routes_enabled` is `true`, you will get 3 additional routes:

```
php artisan route:list

```

Result:

```
GET|HEAD 	box/login
GET|HEAD 	box/callback
GET|HEAD 	box/me

```

You can access  to login with your box account credential, and then you will be redirected to .

Folder Examples
---------------

[](#folder-examples)

Add Box service

```
use Gzai\LaravelBoxAdapter\Facades\Box;

```

### Get Folder Information

[](#get-folder-information)

```
Route::get('box/folder/get', function() {
	$folderId = 000000000000; // you can change to specific folder id box

	// get folder information in box
	return Box::getFolder($folderId);
});

```

### Check Folder Exists

[](#check-folder-exists)

```
Route::get('box/folder/exists', function() {
	$folderId = 000000000000; // you can change to specific folder id box

	// get status folder exists in box
	return Box::folderExists($folderId);
});

```

### Create Folder

[](#create-folder)

```
Route::get('box/folder/create', function() {
	$folderName = 'new_folder';
	$folderId = config('box.folder.parent'); // you can change to specific folder id box

	// create folder in box
	return Box::createFolder($folderName, $folderId);
});

```

### Delete Folder

[](#delete-folder)

```
Route::get('box/folder/delete', function() {
	$folderId = 000000000000; // you can change to specific folder id box

	// delete folder in box
	return Box::deleteFolder($folderId);
});

```

### Get Folder Items

[](#get-folder-items)

```
Route::get('box/folder/items', function() {
	$folderId = 000000000000; // you can change to specific folder id box

	// get folder items in box
	return Box::getFolderItems($folderId);
});

```

### Search Folders By Folder Name

[](#search-folders-by-folder-name)

```
Route::get('box/folder/search', function() {
	$folderName = 'new_folder';
	$folderParentId = config('box.folder.parent'); // you can change to specific folder id box

	// note:
	// Box may take some time to complete its indexing process for a new folder.
	// During this time, the folder you’re searching for through the Search API might not be found until the indexing is finished.

	// search folders by folder name in box
	return Box::getFoldersByName($folderName, $folderParentId);
});

```

### Search &amp; Get Specific Folder ID By Folder Name

[](#search--get-specific-folder-id-by-folder-name)

```
Route::get('box/folder/search/id', function() {
	$folderName = 'new_folder';
	$folderParentId = config('box.folder.parent'); // you can change to specific folder id box

	// note:
	// Box may take some time to complete its indexing process for a new folder.
	// During this time, the folder you’re searching for through the Search API might not be found until the indexing is finished.

	// search specific folder and get the folder id by folder name in box
	return Box::getFolderIdByName($folderName, $folderParentId);
});

```

### Search &amp; Check Folder Exists By Folder Name

[](#search--check-folder-exists-by-folder-name)

```
Route::get('box/folder/search/exists', function() {
	$folderName = 'new_folder';
	$folderParentId = config('box.folder.parent'); // you can change to specific folder id box

	// note:
	// Box may take some time to complete its indexing process for a new folder.
	// During this time, the folder you’re searching for through the Search API might not be found until the indexing is finished.

	// search specific folder and get status folder exists by folder name in box
	return Box::getFolderExistsByName($folderName, $folderParentId);
});

```

### Search &amp; Get Specific Folder By Folder Name

[](#search--get-specific-folder-by-folder-name)

```
Route::get('box/folder/search/exactly', function() {
	$folderName = 'new_folder';
	$folderParentId = config('box.folder.parent'); // you can change to specific folder id box

	// note:
	// Box may take some time to complete its indexing process for a new folder.
	// During this time, the folder you’re searching for through the Search API might not be found until the indexing is finished.

	// search specific folder and get status folder exists by folder name in box
	return Box::getFolderExactlyByName($folderName, $folderParentId);
});

```

Box Search Indexing Reference:

File Examples
-------------

[](#file-examples)

Add Box service

```
use Gzai\LaravelBoxAdapter\Facades\Box;

```

### Get File Information

[](#get-file-information)

```
Route::get('box/file/get', function() {
	$fileId = 000000000000; // you can change to specific file id box

	// get file information in box
	return Box::getFile($fileId);
});

```

### Check File Exists

[](#check-file-exists)

```
Route::get('box/file/exists', function() {
	$fileId = 000000000000; // you can change to specific file id box

	// get status file exists in box
	return Box::fileExists($fileId);
});

```

### Move File

[](#move-file)

```
Route::get('box/file/move', function() {
	$fileId = 000000000000; // you can change to specific file id box
	$parentId = 000000000000; // you can change to specific folder id box

	// move file in box
	return Box::moveFile($fileId, $parentId);

	// or

	$newName = 'new_file_name.jpg'; // you can change to new file name with original file extension

	return Box::moveFile($fileId, $parentId, $newName);
});

```

### Copy File

[](#copy-file)

```
Route::get('box/file/copy', function() {
	$fileId = 000000000000; // you can change to specific file id box
	$parentId = 000000000000; // you can change to specific folder id box

	// copy file in box
	return Box::copyFile($fileId, $parentId);

	// or

	$newName = 'new_file_name.jpg'; // you can change to new file name with original file extension

	return Box::copyFile($fileId, $parentId, $newName);
});

```

### Delete File

[](#delete-file)

```
Route::get('box/file/delete', function() {
	$fileId = 000000000000; // you can change to specific file id box

	// delete file in box
	return Box::deleteFile($fileId);
});

```

### Create Temporary Link

[](#create-temporary-link)

```
Route::get('box/file/temporary_url', function() {
	$fileId = 000000000000; // you can change to specific file id box
	$timeSeconds = 30;

	// create temporary link file in box
	return Box::createTemporaryLink($fileId, $timeSeconds);
});

```

### Search Files By File Name

[](#search-files-by-file-name)

```
Route::get('box/file/search', function() {
	$fileName = '0199B8F2D13E6930B317C121AB41C.pdf';
	$folderParentId = config('box.folder.parent'); // you can change to specific folder id box

	// note:
	// Box may take some time to complete its indexing process for a new file.
	// During this time, the file you’re searching for through the Search API might not be found until the indexing is finished.

	// search files by name in box
	return Box::getFilesByName($fileName, $folderParentId);
});

```

### Search &amp; Get Specific File ID By File Name

[](#search--get-specific-file-id-by-file-name)

```
Route::get('box/file/search/id', function() {
	$fileName = '0199B8F2D13E6930B317C121AB41C.pdf';
	$folderParentId = config('box.folder.parent'); // you can change to specific folder id box

	// note:
	// Box may take some time to complete its indexing process for a new file.
	// During this time, the file you’re searching for through the Search API might not be found until the indexing is finished.

	// seach specific file and get the file id by name in box
	return Box::getFileIdByName($fileName, $folderParentId);
});

```

### Search &amp; Check File Exists By File Name

[](#search--check-file-exists-by-file-name)

```
Route::get('box/file/search/exists', function() {
	$fileName = '0199B8F2D13E6930B317C121AB41C.pdf';
	$folderParentId = config('box.folder.parent'); // you can change to specific folder id box

	// note:
	// Box may take some time to complete its indexing process for a new file.
	// During this time, the file you’re searching for through the Search API might not be found until the indexing is finished.

	// seach specific file and get status file exists by name in box
	return Box::getFileExistsByName($fileName, $folderParentId);
});

```

### Search &amp; Get Specific File Information By File Name

[](#search--get-specific-file-information-by-file-name)

```
Route::get('box/file/search/exactly', function() {
	$fileName = '0199B8F2D13E6930B317C121AB41C.pdf';
	$folderParentId = config('box.folder.parent'); // you can change to specific folder id box

	// note:
	// Box may take some time to complete its indexing process for a new file.
	// During this time, the file you’re searching for through the Search API might not be found until the indexing is finished.

	// seach specific file and get specific file by name in box
	return Box::getFileExactlyByName($fileName, $folderParentId);
});

```

### Upload File

[](#upload-file)

```
Route::get('box/file/upload', function() {
	$file = 'app/public/logo.png';
	$filePath = storage_path($file);
	$folderParentId = 000000000000; // you can change to specific file id box

	return Box::uploadFile($filePath, $folderParentId);
});

```

### Force Download File

[](#force-download-file)

```
Route::get('box/file/download/force', function() {
	$fileId = 000000000000; // you can change to specific file id box

	// download file in box
	return Box::downloadFile($fileId);
});

```

### Save Download File In Directory

[](#save-download-file-in-directory)

```
Route::get('box/file/download/directory', function() {
	$fileId = 000000000000; // you can change to specific file id box

	// download file in box and save it to the directory according to box config download_folder
	return Box::downloadFile($fileId, true);

	// or

	$folderName = 'new_folder';

	// download file in box and save it to the directory according to custom folder name
	return Box::downloadFile($fileId, true, $folderNmae);
});

```

Box Filesystem
--------------

[](#box-filesystem)

Box Adapter can also be used in Laravel Storage

Add Storage

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

```

### Check Directory Exists

[](#check-directory-exists)

```
$path = 'folder_a';

return Storage::disk('box')->directoryExists($path);

```

### Get Files In Root Folder

[](#get-files-in-root-folder)

```
$path = 'folder_a';

return Storage::disk('box')->files($path);

```

### Get Files In Root Folder &amp; Under SubFolder

[](#get-files-in-root-folder--under-subfolder)

```
$path = 'folder_a';

return Storage::disk('box')->allFiles($path);

```

### Get Folder In Root Folder

[](#get-folder-in-root-folder)

```
$path = 'folder_a';

return Storage::disk('box')->directories($path);

```

### Get Folder In Root Folder &amp; Under SubFolder

[](#get-folder-in-root-folder--under-subfolder)

```
$path = 'folder_a';

return Storage::disk('box')->allDirectories($path);

```

### Create Folder

[](#create-folder-1)

```
$path = 'test_folder';

return Storage::disk('box')->makeDirectory($path);

```

### Delete Folder

[](#delete-folder-1)

```
$path = 'test_folder';

return Storage::disk('box')->deleteDirectory($path);

```

### Check File Exists

[](#check-file-exists-1)

```
$path = 'folder_a/01K5B9BGPGDMR5KCS883NM39K3.png';

return Storage::disk('box')->exists($path);

```

### Get File URL

[](#get-file-url)

```
$path = 'folder_c/0199F048051772AD8AF7154E2A33D23A.jpg';

return Storage::disk('box')->url($path);

```

### Create Temporary URL File

[](#create-temporary-url-file)

```
$path = 'folder_c/0199F048051772AD8AF7154E2A33D23A.jpg';
$expiration = now()->addMinutes(5);

return Storage::disk('box')->temporaryUrl($path, $expiration);

```

### Move File

[](#move-file-1)

```
$path_a = 'folder_c/0199F048051772AD8AF7154E2A33D23A.jpg';
$path_b = 'folder_b/0199F048051772AD8AF7154E2A33D23A.jpg';

return Storage::disk('box')->move($path_a, $path_b);

```

### Copy File

[](#copy-file-1)

```
$path_a = 'folder_b/0199F048051772AD8AF7154E2A33D23A.jpg';
$path_b = 'folder_c/0199F048051772AD8AF7154E2A33D23A.jpg';

return Storage::disk('box')->copy($path_a, $path_b);

```

### Upload File

[](#upload-file-1)

```
$fileName = Box::fileName() . '.jpg';
$path = 'folder_c/'. $fileName;

$content = Storage::get('download/0199BDC0C7C9729B8C7850A96CDEAE21.jpg');
Storage::disk('box')->put($path, $content);

// or

$resource = fopen(storage_path('app/download/0199BDC0C7C9729B8C7850A96CDEAE21.jpg'), 'r');
Storage::disk('box')->put($path, $resource);

```

### Delete File

[](#delete-file-1)

```
$path = 'folder_c/0199F0453FCC72DAA0A19FBD63C2B520.jpg';

return Storage::disk('box')->delete($path);

```

### Get File Information

[](#get-file-information-1)

```
$path = 'folder_c/0199F048051772AD8AF7154E2A33D23A.jpg';

return Storage::disk('box')->get($path);

```

### Download File

[](#download-file)

```
$path = 'folder_c/0199F048051772AD8AF7154E2A33D23A.jpg';
$pathExplode = explode('/', $path);
$fileName = last($pathExplode);

return Storage::disk('box')->download($path, $fileName);

```

Filament FileUpload
-------------------

[](#filament-fileupload)

If you are using Laravel Filament, you can easily integrate the Laravel Box Adapter with the `FileUpload` component.

You can add `disk('box')` and use `fileUploadBox()` method in your Filament FileUpload.

Because Box doesn’t have a public asset URL, we set `previewable(false)` method in `fileUploadBox()` to disable file preview.

```
Forms\Components\FileUpload::make('attachment')
    ->disk('box')
    ->directory('folder')
    ->required()
    ->fileUploadBox(),

```

When a file is successfully uploaded to Box, you will receive the `file ID` and `folder ID` Box data in `session`.

You can store these IDs before saving your data to the database.

```

protected function mutateFormDataBeforeCreate(array $data): array
{
    $data['parent_id'] = session()->has('parentIdBox') && !empty(session('parentIdBox')) ? session('parentIdBox') : null;
    $data['file_id'] = session()->has('fileIdBox') && !empty(session('fileIdBox')) ? session('fileIdBox') : null;

	// deleting the parentIdBox & fileIdBox sessions
	session()->forget(['parentIdBox', 'fileIdBox']);

    return $data;
}

```

or you can update these IDs before saving your data to the database.

```
use Illuminate\Database\Eloquent\Model;

```

```
protected function handleRecordUpdate(Model $record, array $data): Model
{
	// you can delete old file in box
	if ( session()->has('fileIdBox') && !empty(session('fileIdBox')) && $data['attachment'] != null ) {
        Box::deleteFile($record->file_id);
    }

    $data['parent_folder_id'] = session()->has('parentIdBox') && !empty(session('parentIdBox')) ? session('parentIdBox') : $record->parent_folder_id;
    $data['file_id'] = session()->has('fileIdBox') && !empty(session('fileIdBox')) ? session('fileIdBox') : $record->file_id;
    $data['attachment'] = ( $data['attachment'] != null ) ? $data['attachment'] : $record->attachment;

	// deleting the parentIdBox & fileIdBox sessions
	session()->forget(['parentIdBox', 'fileIdBox']);

    $record->update($data);

    return $record;
}

```

Since Filament v4 has a different implementation of `saveUploadedFileUsing()` compared to Filament v3, you can pass the `file ID` and `folder ID` Box data using the Laravel `session`.

Change Logs
===========

[](#change-logs)

Please see the [changelog](CHANGELOG)

Contributing
============

[](#contributing)

Contributing are welcome.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance67

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

201d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ec9a182982e091ffaf2a0be98825c36b8c05f4c39236f3bb4a337c3643ef207f?d=identicon)[gzai](/maintainers/gzai)

---

Top Contributors

[![gzai](https://avatars.githubusercontent.com/u/4225733?v=4)](https://github.com/gzai "gzai (4 commits)")

---

Tags

laraveladapterbox

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gzai-laravel-box-adapter/health.svg)

```
[![Health](https://phpackages.com/badges/gzai-laravel-box-adapter/health.svg)](https://phpackages.com/packages/gzai-laravel-box-adapter)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.6k509.9M17.0k](/packages/laravel-framework)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[laravel/vapor-cli

The Laravel Vapor CLI

31310.7M8](/packages/laravel-vapor-cli)[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k84.2M225](/packages/laravel-horizon)[laravel-zero/framework

The Laravel Zero Framework.

3371.4M369](/packages/laravel-zero-framework)[torchlight/torchlight-laravel

A Laravel Client for Torchlight, the syntax highlighting API.

120452.8k11](/packages/torchlight-torchlight-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
