Currently seeking new career opportunities in web development, particularly with Laravel, Hire Me

Build a Dropbox File Manager in Laravel - Part 1 Setup and Folder Listings

David Carr

Laravel Framework Tutorials PHP & MySQL Packages


In this series, we will build a file manager in Laravel that reads and writes to Dropbox. 

Application Register

Before we start on the code we need a Dropbox App registered at

  1. Choose Dropbox API.
  2. For the type of access select Full App. 
  3. Give your app a name.
  4. Select which Account to create the app in (you may only have one option)
  5. Click Create App

Build a Dropbox File Manager in Laravel

Now you have an app registered, there are a few settings that are required, take notice of:

  1. App Key
  2. App Secret

They will both be required in Laravel. There are two options for our integration either use the app with your account only or let users access their Dropbox account.

Option 1 Use your own account only

This is the simpler option all you need to do is click Generate Access Token and copy and paste the code into a .env file:


This means you will only ever be able to use your own account for the integration.

Option 2 Let users access their own account

Let users connect to their own account using Oauth2. This means a user goes to a URL and then is redirected to Dropbox to approve the connection once complete an Access Token will be available to store against the user. The token can be revoked at any time directly from Dropbox.


Install a Dropbox Laravel package

Open a Laravel project (new or existing), we're going to install my Laravel Dropbox package

The complete docs for this package can be found at

composer require daveismyname/laravel-dropbox

In Laravel 5.5 the service provider will automatically get registered. In older versions of the framework just add the service provider in config/app.php file

'providers' => [
    // ...

You can publish the config file with:

php artisan vendor:publish --provider="Daveismyname\Dropbox\DropboxServiceProvider" --tag="config"

You can publish the migration with: (this is required to store the access token)

php artisan vendor:publish --provider="Daveismyname\Dropbox\DropboxServiceProvider" --tag="migrations"

After the migration has been published you can create the tokens tables by running the migration:

php artisan migrate

Ensure you've set the following in your .env file:


Change the urls above as needed I'm choosing to use as my project url.


Use Oauth2 to connect to a users Dropbox Account

Note you should already have authentication setup in Laravel and be logged in. See

Go back to Dropbox App Console, a redirect URL needs setting up.

Go to the Redirect URIs section and add this URL:

This tells Dropbox where to redirect to.

Back in Laravel

In order to start the integration, we need a route that will redirect to Dropbox to start the Oauth2 process. In routes/web.php add:

Route::get('filemanager/oauth', function(){
    return Dropbox::connect();

Now going to /filemanager/oauth in the browser will redirect you to Dropbox.

Since the app on Dropbox has not been published you will see this warning:


Click continue to carry on.

You will then see a screen like this:

Select an account to connect to. You will then be redirected to the URL set in your .env file:


This route has not yet been setup, all routes at this point should only be available when authenticated with Dropbox the Laravel Dropbox package has a simple way of taking care of this with middleware:

Route::group(['middleware' => ['auth', 'DropboxAuthenticated']], function() {

    Route::get('filemanager/{path?}', 'FileManagerController@index')->where('path', '(.*)');


This closure uses a DropboxAuthenticated middleware which ensures you are connected to Dropbox otherwise you will be redirected for approval.

Next, a new route is defined filemanager/{path?} this is a wildcard route meaning it will respond to not only /filemanager but also paths beyond like /filemanager/foldername

Create a new controller called FileManagerController 


namespace App\Http\Controllers;

use Daveismyname\Dropbox\Facades\Dropbox;
use Exception;

class FileManagerController extends Controller
    public function index($path = '')
        $results = Dropbox::files()->listContents($path);

        return view('filemanager.index', compact('results'));

Inside the controller we can access the list of folders and files for a given path by calling:


The $path comes from the route directly.

Pass this to a view called filemanager/index.blade.php and add:



<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">

            <table class="table">
            @foreach($results['entries'] as $row)

                $type = $row['.tag'] == 'folder' ? 'folder' : 'file';
                $name = $row['name'];
                $pathLower = $row['path_lower'];

                    @if ($type == 'folder')
                        <a href='{{ url('filemanager'.$pathLower) }}'><i class="fa fa-folder"></i> {{ $name }}</a><br>
                        {{ $name }}




This forms the layout of the File Manager, let's go through it.

We loop through the files and folders by doing a foreach loop on $results['entries']

Inside the data is an attribute called .tag this will be either file or folder to let's add that to a $type

$type = $row['.tag'] == 'folder' ? 'folder' : 'file';

We also want the name of the file/folder and its path:

$name = $row['name'];
$pathLower = $row['path_lower'];

Listing the files/folders if it's a folder then we should add a link so it's clickable otherwise just show the name.

@if ($type == 'folder')
    <a href='{{ url('filemanager'.$pathLower) }}'><i class="fa fa-folder"></i> {{ $name }}</a><br>
    {{ $name }}

Thanks to the wildcard route for filemanager/{path?) we can access any folder by going to /filemanager/foldername as long as the folder path exists on the dropbox account its contents will be displayed.

Laravel Modules Your Logo Your Logo Your Logo

Become a sponsor

Help support the blog so that I can continue creating new content!


My Latest Book

Modular Laravel Book - Laravel: The Modular way

Learn how to build modular applications with Laravel Find out more

Subscribe to my newsletter

Subscribe and get my books and product announcements.

Learn Laravel with Laracasts

Faster Laravel Hosting

© 2006 - 2024 DC Blog. All code MIT license. All rights reserved.