Skip to content

Instantly share code, notes, and snippets.

@sherbrow
Created February 19, 2017 20:13
Show Gist options
  • Save sherbrow/57f61144eb17e7fab18e66adbe9f8fad to your computer and use it in GitHub Desktop.
Save sherbrow/57f61144eb17e7fab18e66adbe9f8fad to your computer and use it in GitHub Desktop.
Lumen 5.4 subfolder install
BASE_URL=/subfolder
<?php
/**
* Exact copy of vendor/laravel/lumen-framework/src/routing/UrlGenerator.php
* Renamed to LumenUrlGenerator
*/
namespace Laravel\Lumen\Routing;
class LumenUrlGenerator
{
// lumen-framework/src/routing/UrlGenerator.php
}
<?php
/**
* To ease the pain of overriding helpers like url() and route()
* Little hack with LumenUrlGenerator and composer
*/
namespace Laravel\Lumen\Routing;
class UrlGenerator extends LumenUrlGenerator
{
protected function getRootUrl($scheme, $root = null)
{
if (is_null($this->cachedRoot)) {
$this->cachedRoot = $this->app->make('request')->root();
$baseUrl = env('BASE_URL');
if ($baseUrl && strpos($this->cachedRoot, $baseUrl) === FALSE) {
$this->cachedRoot .= $baseUrl;
}
}
return parent::getRootUrl($scheme, $root);
}
}
// ...
$app->group(['namespace' => 'App\Controllers', 'prefix' => env('BASE_URL', '')], function ($app) {
require __DIR__.'/../routes/web.php';
});
// ...
{
"autoload": {
"psr-4": {
"Laravel\\Lumen\\Routing\\": "app/Routing"
}
},
}
<?php
abstract class TestCase extends Laravel\Lumen\Testing\TestCase
{
public function setUp()
{
parent::setUp();
$this->baseUrl = $this->baseUrl . env('BASE_URL', '');
}
}
@sherbrow
Copy link
Author

Since I wasn't going to find an easy fix like laravel/lumen-framework#35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment