dongpo2340 2016-12-09 06:06
浏览 43
已采纳

没有前端的Laravel项目

currently I have a standard Laravel 5 proyect, eg:

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

what I'm trying to do is to take the public and resources folder out from the application and put it them on a different project, and in that way I'll use the laravel part only for backend purposes and the frontend parte I'll manage it on an outside project. e.g.:

 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

Any recomendation or ideas to do it ?

  • 写回答

1条回答 默认 最新

  • duan02143 2016-12-09 08:05
    关注

    Removing (or moving) the Public folder is not a good idea, especially due to the fact that the public/index.php file is the entrypoint for the application.
    I personally use both laravel and lumen for a bunch of my REST-API's and it works great, so that thought is not at all wrong.
    Just ignore the views, don't use them and don't expose them from any controller action, but rather return all data from the controllers as JSON instead.

    This is easily done from the controller actions like:

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

    I would also recommend that you group your routes under a API namespace of some sort:

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

    So now when you call domain.tdl/api/v1/something you will get a neat json response!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值