Skip to content

Instantly share code, notes, and snippets.

@thgs
Created January 27, 2016 23:22
Show Gist options
  • Save thgs/4f4bb4fa054016697018 to your computer and use it in GitHub Desktop.
Save thgs/4f4bb4fa054016697018 to your computer and use it in GitHub Desktop.
laravel-5 wrapper
<?php namespace App\Http\Controllers;
use File;
use App\Http\Requests;
use Illuminate\Http\Request;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('home');
}
protected function getFile($filepath)
{
if (File::isFile($filepath))
{
$ext = pathinfo($filepath, PATHINFO_EXTENSION);
$isPhp = ($ext == 'php');
if ($isPhp)
{
return include($filepath);
}
else
{
return File::get($filepath);
}
}
elseif (File::isDirectory($filepath))
{
// check if there is an index.php there
$filepath .= '/index.php';
return $this->getFile($filepath);
}
else
{
abort(404);
}
}
public function wrap($path)
{
$rootDir = public_path('v1/');
$fileRequested = $rootDir . $path;
return $this->getFile($fileRequested);
}
}
<?php
/*
|--------------------------------------------------------------------------
| Routes File
|--------------------------------------------------------------------------
|
| Here is where you will register all of the routes in an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
return view('welcome');
});
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| This route group applies the "web" middleware group to every route
| it contains. The "web" middleware group is defined in your HTTP
| kernel and includes session state, CSRF protection, and more.
|
*/
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/home', 'HomeController@index');
Route::any('/wrapped/{path}', 'HomeController@wrap')->where('path', '.*');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment