没有前端的 Laravel 项目

fla*_*alf 0 php laravel

目前我有一个标准的 Laravel 5 项目,例如:

 Laravel Directory
     app Directory
     bootstrap Directory
     config Directory
     database Directory
     public Directory
     resources Directory
     routes Directory
     storage Directory
     tests Directory
     vendor Directory
Run Code Online (Sandbox Code Playgroud)

我想要做的是从应用程序中取出 public 和 resources 文件夹并将它们放在不同的项目中,这样我将仅将 laravel 部分用于后端目的,而前端部分我将在外部项目上管理它。例如:

 Laravel Directory
     app Directory
     bootstrap Directory
     config Directory
     database Directory
     routes Directory
     storage Directory
     tests Directory
     vendor Directory

Frontend project
     index.html
     app folder
     css folder
     assets
Run Code Online (Sandbox Code Playgroud)

有什么建议或想法可以做到吗?

Jit*_*ite 8

删除(或移动)公用文件夹不是一个好主意,尤其是因为该public/index.php文件是应用程序的入口点。
我个人将 laravel 和 lumen 用于我的一堆 REST-API,而且效果很好,所以这种想法并没有错。
只需忽略视图,不要使用它们,也不要从任何控制器操作中公开它们,而是从控制器返回所有数据JSON

这可以通过控制器操作轻松完成,例如:

public function getSomethingAction() {
    return response()->json([
        "some" => "property"
    ]);
}
// Which will produce the following json (including headers and all):
{
    "some": "property"
}
Run Code Online (Sandbox Code Playgroud)

我还建议您group将路由置于某种 API 命名空间下:

Route::group(["prefix" => "api/v1"], function() {
    Route::get('something'...
});
Run Code Online (Sandbox Code Playgroud)

所以现在当你打电话时,domain.tdl/api/v1/something你会得到一个整洁的 json 响应!