Laravel: How to Route to Public file

后端 未结 2 954
萌比男神i
萌比男神i 2021-01-04 10:23

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

In the application/routes.php,



        
2条回答
  •  感动是毒
    2021-01-04 10:41

    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"); });
    

提交回复
热议问题