Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: How to Route to Public file

In Laravel, is it possible to redirect to a public/testFile.php, through routing?

In the application/routes.php,

Route::get('/', function()
{
    //'How to point to public/testFile.php'

});

Have an existing Project, But want to do Only the NEW MODULES in Laravel. So copied the Existing project under Public/

like image 981
Avisek Chakraborty Avatar asked Apr 05 '13 14:04

Avisek Chakraborty


2 Answers

You are completely defeating the purpose of the framework by doing this, but if you really want to...

Route::get("/", function() {
    ob_start();
    require(path("public")."testFile.php");
    return ob_get_clean();
});

This will return the stdout output of the file. If instead you have a return value already in the script, knock out ob_start and the return call.

Redirects are done as follows:

Route::get("/", function() { return Redirect::to("testFile.php"); });
like image 174
Sébastien Renauld Avatar answered Nov 12 '22 00:11

Sébastien Renauld


Route::get('/', function()
{
    include public_path().'testFile.php';
});

If you want to Redirect then use return Redirect::to('testFile.php')

But I don't get why you want to do this weird thing.

I think you are using Laravel 3 (as you mentioned application/...), there public_path() is path('public').

like image 10
Muhammad Usman Avatar answered Nov 12 '22 00:11

Muhammad Usman