-
-
Notifications
You must be signed in to change notification settings - Fork 205
Laravel & Lumen Integration
Ankit Pokhrel edited this page Nov 23, 2020
·
9 revisions
-
Add
ankitpokhrel/tus-php
as your dependency.$ composer require ankitpokhrel/tus-php
-
Create a service provider, say
TusServiceProvider.php
or you can also use existing service provider.If you create a new service provider, do not forget to add it to
config/app.php
.<?php namespace App\Providers; use TusPhp\Tus\Server as TusServer; use Illuminate\Support\ServiceProvider; class TusServiceProvider extends ServiceProvider { // ... /** * Register the application services. * * @return void */ public function register() { $this->app->singleton('tus-server', function ($app) { $server = new TusServer('redis'); $server ->setApiPath('/tus') // tus server endpoint. ->setUploadDir(storage_path('app/public/uploads')); // uploads dir. return $server; }); } // ... }
-
Add a route to serve the request.
// routes/web.php Route::any('/tus/{any?}', function () { return app('tus-server')->serve(); })->where('any', '.*');
-
For Laravel, open
VerifyCsrfToken.php
and exclude your tus server endpoint from Laravel’s CSRF validation.// ... class VerifyCsrfToken extends BaseVerifier { // ... protected $except = [ '/tus', '/tus/*', ]; }
Note that disabling the CSRF validation is not recommended and you should use
X-CSRF-TOKEN
header in an ideal case. See this and #292.You can now access tus server endpoints at
http://yourapp.dev/tus
orhttp://yourapp.dev/tus/
.