Ok, I finally get the answer.
Create an AssetsController
controller like this:
<?php
namespace app\Http\Controllers;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Response;
use app\Http\Controllers\Controller;
use Redirect;
class AssetsController extends Controller
{
/**
* Get asset url and return response based on file type
*
* @param $filename
* @return mixed
*/
public function data($filename)
{
$path = public_path().'/'; // You need to change your public path before this
$path = $path.$filename;
$file = File::get($path);
$type = File::mimeType($path);
$response = Response::make($file, 200);
$response->header("Content-Type", $type);
return $response;
}
}
So now, I need to change asset helper function. I created a ServiceProvider to make the magic Register under config/app.php:
<?php
namespace app\Providers;
use Illuminate\Support\ServiceProvider;
class SitePathServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Reset asset function
*
* @param $path
* @return string
*/
public function asset($path)
{
return url('assets/'.$path);
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//
}
}
The trick is to do a route helper:
Route::get('/assets/{params}', 'AssetsController@data')->where('params', '.*');
This route catch all url like:
http://www.example.com/assets/demo.jpg
http://www.example.com/assets/uploads/demo.jpg
http://www.example.com/assets/large/structure/folder/demo.jpg
I know it's something complicated, but works like a charm.
King regards